Skip to main content

Hook and simulate keyboard events on Windows and Linux

Project description

Take full control of your keyboard with this small Python library. Hook global events, register hotkeys, simulate key presses and much more.

Features

  • Global event hook on all keyboards (captures keys regardless of focus).

  • Listen and sends keyboard events.

  • Works with Windows and Linux (requires sudo).

  • Pure Python, no C modules to be compiled.

  • Zero dependencies. Trivial to install and deploy, just copy the files.

  • Python 2 and 3.

  • Complex hotkey support (e.g. Ctrl+Shift+M, Ctrl+Space) with controllable timeout.

  • Includes high level API (e.g. `record <#keyboard.record>`__ and `play <#keyboard.play>`__, `add_abbreviation <#keyboard.add_abbreviation>`__).

  • Maps keys as they actually are in your layout, with full internationalization support (e.g. Ctrl+ç).

  • Events automatically captured in separate thread, doesn’t block main program.

  • Tested and documented.

  • Doesn’t break accented dead keys (I’m looking at you, pyHook).

  • Mouse support coming soon.

This program makes no attempt to hide itself, so don’t use it for keyloggers.

Usage

Install the PyPI package:

$ sudo pip install keyboard

or clone the repository (no installation required, source files are sufficient):

$ git clone https://github.com/boppreh/keyboard

Then check the API docs to see what features are available.

Example

import keyboard

# Press PAGE UP then PAGE DOWN to type "foobar".
keyboard.add_hotkey('page up, page down', lambda: keyboard.write('foobar'))

keyboard.press_and_release('shift+s, space')

# Blocks until you press esc.
keyboard.wait('esc')

# Record events until 'esc' is pressed.
recorded = keyboard.record(until='esc')
# Then replay back at three times the speed.
keyboard.play(recorded, speed_factor=3)

Known limitations:

  • Events generated under Windows don’t report device id (event.device == None).

  • Media keys are not hooked (neither Linux nor Windows report them as normal keys).

  • Currently no way to suppress keys.

  • Requires root on Linux.

  • Other applications, such as some games, may register hooks that swallow all key events. In this case keyboard will be unable to report events.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keyboard-0.9.4.zip (34.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

keyboard-0.9.4.win-amd64.zip (80.8 kB view details)

Uploaded Source

keyboard-0.9.4.win-amd64.exe (624.3 kB view details)

Uploaded Source

keyboard-0.9.4-py2.py3-none-any.whl (32.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file keyboard-0.9.4.zip.

File metadata

  • Download URL: keyboard-0.9.4.zip
  • Upload date:
  • Size: 34.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for keyboard-0.9.4.zip
Algorithm Hash digest
SHA256 5b9c187d8ab89a4c623334b3c1b345fd08ec488b62acc7456ec0406dc1c86c39
MD5 8e417e9be18b5c8d0487cefb11030804
BLAKE2b-256 b75acf42b332a352daea21eba509e525a57369789380769a8316d1ea107ab944

See more details on using hashes here.

File details

Details for the file keyboard-0.9.4.win-amd64.zip.

File metadata

File hashes

Hashes for keyboard-0.9.4.win-amd64.zip
Algorithm Hash digest
SHA256 c8232743cef4f49b12604be8523cb5b3417d53203f2876b3d5f180e1377846cb
MD5 721852b9dd7d60dd184edf8a6b9132d9
BLAKE2b-256 f17a5f981b2092718e8e67bf95920c2e2cd78598221a56d1ae08a6a02dd587c5

See more details on using hashes here.

File details

Details for the file keyboard-0.9.4.win-amd64.exe.

File metadata

File hashes

Hashes for keyboard-0.9.4.win-amd64.exe
Algorithm Hash digest
SHA256 94b2921e7335e20a80b9420203dcca48bcdcf8a07b92267bd4ef22e42bc37452
MD5 f31618e17f2ac311659cbd16188f1322
BLAKE2b-256 cbb9e9ff963b2b63bd3ec77a6f8d131eea5e9d11e26849b029c8ff3050278128

See more details on using hashes here.

File details

Details for the file keyboard-0.9.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for keyboard-0.9.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d8a20cc577096452921537f4f96d4f88c136c9bc512fbca34b702a56a75c1af5
MD5 ad5dffcbbacbfeb82b4ab5ddf36be17f
BLAKE2b-256 6cd9e74193922d10e437cc0a7ca56d302aa70a6465bef278616decab254e2395

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page