-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoystick_application.py
More file actions
38 lines (32 loc) · 1.18 KB
/
joystick_application.py
File metadata and controls
38 lines (32 loc) · 1.18 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
from PyQt5.QtCore import *
from myjoystick import MyJoystick
class MyJoystickEx(MyJoystick):
def __init__(self, parent=None, cbJoyPos=None):
super(MyJoystickEx, self).__init__(parent, cbJoyPos)
self.setFocusPolicy(Qt.StrongFocus)
self.keyPressed = False
self.posX, self.posY = 0, 0
def keyPressEvent(self, event):
self.keyPressed = True
posX, posY = 0, 0
if event.key() == Qt.Key_Right:
posX = 1
elif event.key() == Qt.Key_Left:
posX = -1
elif event.key() == Qt.Key_Up:
posY = -1
elif event.key() == Qt.Key_Down:
posY = 1
self.posX, self.posY = posX, posY
return super().keyPressEvent(event)
def keyReleaseEvent(self, event):
self.keyPressed = False
return super().keyReleaseEvent(event)
def timeout(self):
sender = self.sender()
if id(sender) == id(self.timer):
if self.cbJoyPos:
if self.keyPressed:
self.cbJoyPos((self.posX, self.posY))
else:
self.cbJoyPos(self._joystickPosition())