forked from emmatyping/pyhooked
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
19 lines (15 loc) · 798 Bytes
/
example.py
File metadata and controls
19 lines (15 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from pyhooked import Hook, KeyboardEvent, MouseEvent
def handle_events(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:
print("Ctrl + A was pressed")
elif args.current_key == 'Q' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key:
hk.stop()
print('Quitting.')
if isinstance(args, MouseEvent):
if args.mouse_x == 300 and args.mouse_y == 400:
print("Mouse is at (300,400")
hk = Hook() # make a new instance of PyHooked
hk.handler = handle_events # add a new shortcut ctrl+a, or triggered on mouseover of (300,400)
hk.hook() # hook into the events, and listen to the presses