Skip to main content

A simple cross-platform library to block and unblock keyboard input.

Project description

KeyboardGate

A simple, cross-platform Python library to temporarily block and unblock keyboard input in the terminal.

This can be useful for scenarios where you want to prevent user input during a critical operation or create a more controlled command-line interface.

How to Use

Install the package from PyPI:

pip install KeyboardGate

Here is a basic example of how to use KeyboardGate:

from KeyboardGate import KeyboardGate
import time

# Initialize the gate
gate = KeyboardGate()

print("Keyboard input will be disabled for 3 seconds.")
gate.KeyboardGateDisable()
time.sleep(3)
gate.KeyboardGateEnable()
print("Keyboard input is now enabled.")

# You can also use it as a context manager
with KeyboardGate():
    print("Input is disabled inside this block.")
    time.sleep(2)
print("Input is automatically re-enabled outside the 'with' block.")

How It Works

  • On Unix-like systems (Linux, macOS): It modifies the terminal's attributes (termios) to turn off ECHO, which prevents characters from being displayed.
  • On Windows: It uses the msvcrt module to consume any keyboard events that are waiting in the input buffer.

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

keyboardgate-0.0.2.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

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

keyboardgate-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file keyboardgate-0.0.2.tar.gz.

File metadata

  • Download URL: keyboardgate-0.0.2.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for keyboardgate-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2503bf95b41d7f832f6d3084aff5a83c5e0dcb001d7d4049ce643662ff9d5cb1
MD5 e86acdc55f3004a15cb91c9852efb224
BLAKE2b-256 09ae8bb26a0c71ce5ace0ed3aac009fed681b3c3d5fe6679c756a905e78f9372

See more details on using hashes here.

File details

Details for the file keyboardgate-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: keyboardgate-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for keyboardgate-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 08d762b82adb482ad7bda17aae25bd8ed8f0b0e4a5f12d524d0e04fb30b3b3af
MD5 24c0a7f5e93804e47180fa11f9881eae
BLAKE2b-256 4505650a4283e3a9941fffba5df305c4dbd174906d85d33f179c1fc12846f23c

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