Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import sleep
- from pynput import mouse, keyboard
- def constrain(val, min_val, max_val):
- return min(max_val, max(min_val, val))
- def on_press(key):
- global end
- global correct
- if key == keyboard.Key.end: end = True
- if key == keyboard.Key.tab: correct = not correct
- CPS = 300 # Corrections Per Second
- rect = {"top_left": {"x": 0, "y": 0},
- "bot_right": {"x": 1350, "y": 767}}
- end = False
- correct = True
- mouse = mouse.Controller()
- kb_listener = keyboard.Listener(on_press = on_press)
- kb_listener.start()
- while not end:
- sleep(1/CPS)
- if correct:
- x, y = mouse.position
- mouse.position = (constrain(x, rect["top_left"]["x"], rect["bot_right"]["x"]),
- constrain(y, rect["top_left"]["y"], rect["bot_right"]["y"]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement