{"id":24470,"library":"python-yakh","title":"Yet Another Keypress Handler","description":"A cross-platform library for handling keypress events in the terminal. Supports both Unix and Windows systems. Current version: 0.4.1. Release cadence: irregular.","status":"active","version":"0.4.1","language":"python","source_language":"en","source_url":"https://github.com/petereon/yakh","tags":["keypress","terminal","input","cross-platform"],"install":[{"cmd":"pip install python-yakh","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Common mistake: import from wrong module. The handler is directly in 'yakh'.","wrong":"from yakh.keypress import KeypressHandler","symbol":"KeypressHandler","correct":"from yakh import KeypressHandler"},{"note":"Correct import for key constants like keys.ENTER, keys.ESC, etc.","symbol":"keys","correct":"from yakh import keys"}],"quickstart":{"code":"from yakh import KeypressHandler\n\ndef on_key(key):\n    print(f\"Pressed: {key}\")\n\nhandler = KeypressHandler()\nhandler.key_pressed += on_key\nhandler.start()\nimport time\ntime.sleep(5)\nhandler.stop()","lang":"python","description":"Simple example: listen for keypresses for 5 seconds and print each key."},"warnings":[{"fix":"Use a try/finally block or context manager to stop the handler.","message":"The KeypressHandler runs in a separate thread. Ensure you stop the handler properly to avoid hanging processes. Always call handler.stop() before exiting.","severity":"gotcha","affected_versions":"all"},{"fix":"Register handler.stop() with atexit.register() or use a context manager.","message":"On Unix, the handler sets the terminal to raw mode. If the program crashes or exits without calling stop(), the terminal may be left in a broken state. Use atexit or signal handlers to restore terminal settings.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to 0.2.1+ using pip install --upgrade python-yakh","message":"In version 0.2.1 and earlier, the handler had a bug where the fd was not reset to blocking state. Make sure to use 0.2.1 or later.","severity":"deprecated","affected_versions":"<0.2.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure you installed 'python-yakh' and import as 'from yakh import KeypressHandler'.","cause":"Probably installed the wrong package or imported incorrectly. The package is 'python-yakh' but import is 'yakh'.","error":"AttributeError: module 'yakh' has no attribute 'KeypressHandler'"},{"fix":"Run the script in a proper terminal or check with sys.stdin.isatty() before using yakh.","cause":"Occurs on some Unix systems when the terminal is not a TTY (e.g., running in a pipe or IDE terminal).","error":"OSError: [Errno 25] Inappropriate ioctl for device"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}