forked from jwaschkau/ragetracks
/
keyboarddevice.py
51 lines (37 loc) · 1.49 KB
/
keyboarddevice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
##############################################################
# this module wraps around the panda keybpard event handling
# and holds the information about all (un-) pressed keys
##############################################################
# from panda3d.core import *
from direct.showbase.ShowBase import ShowBase
from direct.directnotify.DirectNotify import DirectNotify
# ---------------------------------------------------------
# ---------------------------------------------------------
# ---------------------------------------------------------
class KeyboardDevice(object):
'''
This class holds data about the keyboard
'''
def __init__(self):
'''
'''
self._notify = DirectNotify().newCategory("Input")
self._notify.info("New Keyboard-Object created: %s" % (self))
base.buttonThrowers[0].node().setButtonUpEvent("button-up")
base.buttonThrowers[0].node().setButtonDownEvent("button")
base.accept("button-up", self.setKey, [False])
base.accept("button", self.setKey, [True])
self.keys = {}
# ---------------------------------------------------------
def setKey(self, value, key):
'''
'''
self.keys[key] = value
# print [key, self.keys[key]]
# ---------------------------------------------------------
if __name__ == "__main__":
# from panda3d.core import *
# from direct.showbase.ShowBase import ShowBase
sb = ShowBase()
k = KeyboardDevice()
sb.run()