DESCRIPTION.rst 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. keyboard
  2. ========
  3. Take full control of your keyboard with this small Python library. Hook
  4. global events, register hotkeys, simulate key presses and much more.
  5. Features
  6. --------
  7. - Global event hook on all keyboards (captures keys regardless of
  8. focus).
  9. - **Listen** and **sends** keyboard events.
  10. - Works with **Windows** and **Linux** (requires sudo), with
  11. experimental **OS X** support (thanks @glitchassassin!).
  12. - **Pure Python**, no C modules to be compiled.
  13. - **Zero dependencies**. Trivial to install and deploy, just copy the
  14. files.
  15. - **Python 2 and 3**.
  16. - Complex hotkey support (e.g. ``Ctrl+Shift+M, Ctrl+Space``) with
  17. controllable timeout.
  18. - Includes **high level API** (e.g. `record <#keyboard.record>`__ and
  19. `play <#keyboard.play>`__,
  20. `add\_abbreviation <#keyboard.add_abbreviation>`__).
  21. - Maps keys as they actually are in your layout, with **full
  22. internationalization support** (e.g. ``Ctrl+ç``).
  23. - Events automatically captured in separate thread, doesn't block main
  24. program.
  25. - Tested and documented.
  26. - Doesn't break accented dead keys (I'm looking at you, pyHook).
  27. - Mouse support available via project
  28. `mouse <https://github.com/boppreh/mouse>`__ (``pip install mouse``).
  29. This program makes no attempt to hide itself, so don't use it for
  30. keyloggers.
  31. Usage
  32. -----
  33. Install the `PyPI package <https://pypi.python.org/pypi/keyboard/>`__:
  34. ::
  35. $ sudo pip install keyboard
  36. or clone the repository (no installation required, source files are
  37. sufficient):
  38. ::
  39. $ git clone https://github.com/boppreh/keyboard
  40. Then check the `API docs <https://github.com/boppreh/keyboard#api>`__ to
  41. see what features are available.
  42. Example
  43. -------
  44. ::
  45. import keyboard
  46. keyboard.press_and_release('shift+s, space')
  47. keyboard.write('The quick brown fox jumps over the lazy dog.')
  48. # Press PAGE UP then PAGE DOWN to type "foobar".
  49. keyboard.add_hotkey('page up, page down', lambda: keyboard.write('foobar'))
  50. # Blocks until you press esc.
  51. keyboard.wait('esc')
  52. # Record events until 'esc' is pressed.
  53. recorded = keyboard.record(until='esc')
  54. # Then replay back at three times the speed.
  55. keyboard.play(recorded, speed_factor=3)
  56. # Type @@ then press space to replace with abbreviation.
  57. keyboard.add_abbreviation('@@', 'my.long.email@example.com')
  58. # Block forever.
  59. keyboard.wait()
  60. Known limitations:
  61. ------------------
  62. - Events generated under Windows don't report device id
  63. (``event.device == None``).
  64. `#21 <https://github.com/boppreh/keyboard/issues/21>`__
  65. - Linux doesn't seem to report media keys.
  66. `#20 <https://github.com/boppreh/keyboard/issues/20>`__
  67. - Currently no way to suppress keys ('catch' events and block them).
  68. `#22 <https://github.com/boppreh/keyboard/issues/22>`__
  69. - To avoid depending on X the Linux parts reads raw device files
  70. (``/dev/input/input*``) but this requries root.
  71. - Other applications, such as some games, may register hooks that
  72. swallow all key events. In this case ``keyboard`` will be unable to
  73. report events.