Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pynput import keyboard
- from pynput.keyboard import Controller, Key
- import time, threading
- shift = False
- keycon = Controller()
- def set_interval(func, sec):
- def func_wrapper():
- set_interval(func, sec)
- func()
- t = threading.Timer(sec, func_wrapper)
- t.start()
- return t
- def on_press(key):
- global shift
- if str(key) == "Key.shift": shift = True
- def on_release(key):
- global shift
- if str(key) == "Key.shift": shift = False
- def check_shift():
- if shift:
- print("Doing action")
- keycon.press("w")
- keycon.release("w")
- else:
- print("Not doing action")
- a = set_interval(check_shift, 0.01)
- # Collect events until released
- with keyboard.Listener(
- on_press=on_press,
- on_release=on_release) as listener:
- listener.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement