sshkeyboard is a small, cross-platform Python library designed for capturing key presses and releases, primarily intended for use within SSH sessions but also functional in local terminal environments. It provides simple callback mechanisms for handling key events, enabling interactive command-line applications. The current version is 2.3.1, with ongoing maintenance for bug fixes and compatibility.
pip install sshkeyboardVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up `sshkeyboard` to listen for key presses and releases for a specified duration (5 seconds). It defines two callback functions, `on_press` and `on_release`, which are invoked when a key event occurs.
If using `until` locally, install `pynput`: `pip install pynput`.
Test your application in various target environments. Some terminals may require specific settings or remapping to pass through complex key combinations.
Avoid using `sudo` unless absolutely necessary. If elevated privileges are required for other parts of your script, consider running the key listening component as a non-root user or investigating specific `sudo` configuration for terminal input.
Install the library using pip: `pip install sshkeyboard`
Install the optional dependency `pynput`: `pip install pynput`
Try using a different terminal emulator (e.g., Alacritty, Kitty, Windows Terminal, xterm). Ensure your terminal settings are not remapping or consuming these key events. In some cases, configuring `stty` or `terminfo` might be necessary, especially for older SSH servers.