Advertisement
metalx1000

Python Grab Key Presses

Dec 24th, 2022
1,586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (c) 2022 Kris Occhipinti https://filmsbykris.com.
  4. #
  5. # This program is free software: you can redistribute it and/or modify  
  6. # it under the terms of the GNU General Public License as published by  
  7. # the Free Software Foundation, version 3.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #
  17.  
  18. from pynput.keyboard import Key, Listener
  19.  
  20. def pressed(key):
  21.  
  22.     print('\nKey Pressed {0}'.format( key))
  23.  
  24.     if key == Key.esc:
  25.         quit()
  26.  
  27. with Listener(on_press = pressed) as listener:  
  28.     listener.join()
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement