Advertisement
Guest User

keyboard listener

a guest
Mar 17th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. from pynput import keyboard //you used pynput right??
  2. from pynput.mouse import Button, Controller
  3. mouse = Controller() //mouse is easier to type than Controller....
  4. def on_press(key):
  5. if format(key.char) == 'w': //checks for your key
  6. mouse.position = (400,200) //changes mouse position
  7. if key == keyboard.Key.esc: //if you press escape you quit the program
  8. return False
  9. else:
  10. return True
  11.  
  12. def listen():
  13. with keyboard.Listener( //start the listener. this is a deamon that registers keyboard events and uses minimal cpu
  14. on_press=on_press) as listener:
  15. listener.join()
  16.  
  17. listen() //starts the listen script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement