SSH Keyboard Input Capture

2.3.1 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

from sshkeyboard import listen_keyboard
import time

def on_press(key):
    print(f"Key '{key}' pressed")

def on_release(key):
    print(f"Key '{key}' released")

print("Listening for 5 seconds... Press any key.")
# Listens for key presses and releases for a duration of 5 seconds
listen_keyboard(on_press=on_press, on_release=on_release, until='5 seconds')
print("Finished listening.")

view raw JSON →