forked from emmatyping/pyhooked
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_gui.py
33 lines (27 loc) · 1002 Bytes
/
example_gui.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
import sys
from pyhooked import Hook, KeyboardEvent
import threading
from PySide.QtCore import *
from PySide.QtGui import *
class MyWindow(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.label = QLabel(self)
self.label.setText('A PySide Window')
self.resize(640, 480)
hk = Hook() # make a new instance of PyHooked
hk.handler = self.foo # set the handler function
# thread the call to hook, otherwise we block the GUI
thread = threading.Thread(target=hk.hook)
# start hooking
thread.start()
def foo(self, args):
if isinstance(args, KeyboardEvent):
print(args.key_code)
if args.current_key == 'A' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key:
self.label.setText("Ctrl + A was pressed")
if __name__ == "__main__":
app = QApplication(sys.argv)
w = MyWindow()
w.show()
sys.exit(app.exec_())