forked from sofa-framework/SofaPython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyEvents.py
More file actions
52 lines (46 loc) · 1.97 KB
/
keyEvents.py
File metadata and controls
52 lines (46 loc) · 1.97 KB
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
52
import Sofa.Core
from Sofa.constants import *
functionDict = {
# Arrows
Key.leftarrow : lambda:print("You pressed the left arrow"),
Key.rightarrow : lambda:print("You pressed the right arrow"),
Key.uparrow : lambda:print("You pressed the up arrow"),
Key.downarrow : lambda:print("You pressed the down arrow"),
# Special caracters
Key.space: lambda:print("You pressed the space"),
Key.plus: lambda:print("You pressed the plus"),
Key.minus: lambda:print("You pressed the minux"),
# Letters
Key.I: lambda:print("You pressed the letter I"),
# KeyPad
Key.KP_0: lambda:print("You pressed the number 0 on the keypad"),
Key.KP_1: lambda:print("You pressed the number 1 on the keypad"),
Key.KP_2: lambda:print("You pressed the number 2 on the keypad"),
Key.KP_3: lambda:print("You pressed the number 3 on the keypad"),
Key.KP_4: lambda:print("You pressed the number 4 on the keypad"),
Key.KP_5: lambda:print("You pressed the number 5 on the keypad"),
Key.KP_6: lambda:print("You pressed the number 6 on the keypad"),
Key.KP_7: lambda:print("You pressed the number 7 on the keypad"),
Key.KP_8: lambda:print("You pressed the number 8 on the keypad"),
Key.KP_9: lambda:print("You pressed the number 9 on the keypad")
}
class KeyPressedController(Sofa.Core.Controller):
""" This controller monitors key movements.
Press ctrl and a key to test it!
"""
def __init__(self, *args, **kwargs):
Sofa.Core.Controller.__init__(self, *args, **kwargs)
self.listening = True
self.name = "keyPressedController"
def onKeypressedEvent(self, event):
if event['key'] in functionDict:
functionDict[event['key']]()
else:
print("You pressed the key : " + event['key'])
def onKeyreleasedEvent(self, event):
print("You released a key!")
def createScene(root):
root.bbox = [[-1, -1, -1],[1,1,1]]
root.addObject('DefaultAnimationLoop')
root.addObject(KeyPressedController(name = "MyController"))
return root