Skip to content

Instantly share code, notes, and snippets.

@dmn001
Last active June 1, 2026 11:02
Show Gist options
  • Select an option

  • Save dmn001/3ec1ffa635524bd1c213dc7f7585199d to your computer and use it in GitHub Desktop.

Select an option

Save dmn001/3ec1ffa635524bd1c213dc7f7585199d to your computer and use it in GitHub Desktop.
A Python script to paste text from clipboard char by char (updated shortcut to Ctrl + backtick)
import keyboard
import pyperclip
import time
import threading
def handle_paste():
def _paste():
# 1. Force the OS to see 'ctrl' as released immediately
# This fixes the "sticking" issue
keyboard.release('ctrl')
# 2. Wait for physical keys to be let go
while keyboard.is_pressed('ctrl') or keyboard.is_pressed('`'):
time.sleep(0.01)
# 3. Brief pause to ensure the target window is ready for input
time.sleep(0.1)
text = pyperclip.paste()
if text:
# If the text is very long, keyboard.write can be slow.
# For short strings, this is fine.
keyboard.write(text)
# 4. Final safety release
keyboard.release('ctrl')
threading.Thread(target=_paste, daemon=True).start()
# We use a slight delay or remove suppress=True if you notice lag
# while typing normally.
keyboard.add_hotkey('ctrl+`', handle_paste, suppress=True)
print("Active. Press Ctrl+` to paste. Press Ctrl+Esc to stop.")
keyboard.wait('ctrl+esc')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment