SHOW:
|
|
- or go back to the newest paste.
| 1 | from pynput import keyboard | |
| 2 | from pynput.mouse import Button, Controller | |
| 3 | import time, threading | |
| 4 | ||
| 5 | right_click = False | |
| 6 | mouse = Controller() | |
| 7 | ||
| 8 | def set_interval(func, sec): | |
| 9 | def func_wrapper(): | |
| 10 | set_interval(func, sec) | |
| 11 | func() | |
| 12 | t = threading.Timer(sec, func_wrapper) | |
| 13 | t.start() | |
| 14 | return t | |
| 15 | ||
| 16 | ||
| 17 | def on_press(key): | |
| 18 | global right_click | |
| 19 | - | if str(key) == "Key.shift": right_click = True |
| 19 | + | if str(key) == "Key.space": right_click = True |
| 20 | ||
| 21 | ||
| 22 | def on_release(key): | |
| 23 | global right_click | |
| 24 | - | if str(key) == "Key.shift": right_click = False |
| 24 | + | if str(key) == "Key.space": right_click = False |
| 25 | ||
| 26 | ||
| 27 | def check_press(): | |
| 28 | if right_click: | |
| 29 | mouse.press(Button.right) | |
| 30 | mouse.release(Button.right) | |
| 31 | ||
| 32 | ||
| 33 | a = set_interval(check_press, 0.001) | |
| 34 | ||
| 35 | # Collect events until released | |
| 36 | with keyboard.Listener( | |
| 37 | on_press=on_press, | |
| 38 | on_release=on_release) as listener: | |
| 39 | listener.join() |