-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshiftCursor.py
More file actions
31 lines (27 loc) · 833 Bytes
/
shiftCursor.py
File metadata and controls
31 lines (27 loc) · 833 Bytes
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
from pynput import keyboard
from pynput.mouse import Controller
# Set up mouse controller
mouse = Controller()
# Step size in pixels
STEP = 16
# Movement logic
def on_press(key):
try:
if key.char == 'w':
x, y = mouse.position
mouse.position = (x, y - STEP)
elif key.char == 's':
x, y = mouse.position
mouse.position = (x, y + STEP)
elif key.char == 'a':
x, y = mouse.position
mouse.position = (x - STEP, y)
elif key.char == 'd':
x, y = mouse.position
mouse.position = (x + STEP, y)
except AttributeError:
# Ignore special keys like shift, ctrl, etc.
pass
# Start listening
with keyboard.Listener(on_press=on_press) as listener:
listener.join()