-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouseKeyboard.py
More file actions
50 lines (42 loc) · 1.11 KB
/
mouseKeyboard.py
File metadata and controls
50 lines (42 loc) · 1.11 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
# imports
import pynput
from pynput.keyboard import Key, Controller
from pynput.mouse import Button
from pynput import keyboard, mouse
# vars
x = 0
y = 0
# create an instance of the mouse controller
mController = pynput.mouse.Controller()
# create an instance of the keyboard controller
kController = pynput.mouse.Controller()
# moving the mouse
def on_release(key):
global x, y
if key == keyboard.Key.up:
x = 0
y = -10
print("up pressed")
mController.move(x, y)
if key == keyboard.Key.down:
x = 0
y = 10
print("down pressed")
mController.move(x, y)
if key == keyboard.Key.left:
x = -10
y = 0
print("left pressed")
mController.move(x, y)
if key == keyboard.Key.right:
x = 10
y = 0
print("right pressed")
mController.move(x, y)
if key == keyboard.Key.esc:
listener.stop()
if key == pynput.keyboard.KeyCode(char="q"):
kController.click(Button.left)
# listening... in a non-blocking fashion:
listener = keyboard.Listener(on_release=on_release)
listener.start()