Skip to content

Instantly share code, notes, and snippets.

@Winand
Last active June 22, 2026 11:42
Show Gist options
  • Select an option

  • Save Winand/55f5269d28e34efc79911e31d93996d2 to your computer and use it in GitHub Desktop.

Select an option

Save Winand/55f5269d28e34efc79911e31d93996d2 to your computer and use it in GitHub Desktop.
Automatically type a stored password via a hotkey
"""
Automatically type a stored password via a hotkey.
Usage:
uv run passtype.py password - save a new password in keyring
uv run passtype.py - wait for Alt+Ctrl+Shift+P hotkey to type password
"""
# /// script
# requires-python = ">=3.14"
# dependencies = [
# "keyboard>=0.13.5",
# "keyring>=25.7.0",
# ]
# ///
import getpass
import time
import sys
import keyboard
import keyring
HOTKEY = "Alt+Ctrl+Shift+P"
SERVICE = "passtype"
def type_passw():
pwd = keyring.get_password(SERVICE, SERVICE)
if not pwd:
print(f"Password for '{SERVICE}' not found")
return
#time.sleep(.3) # time to release hotkey ?
keyboard.write(pwd, delay=.03, restore_state_after=False)
keyboard.press("Enter")
def main() -> None:
if sys.argv[-1] == "password":
pwd = getpass.getpass("New password: ")
keyring.set_password(SERVICE, SERVICE, pwd)
else:
keyboard.add_hotkey(HOTKEY, type_passw)
print("Press Ctrl+C to exit")
keyboard.wait()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment