Guest User

Mini control character keyboard

a guest
Dec 9th, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. import tkinter as tk
  2. import subprocess
  3. import time
  4.  
  5. # Store the "safe spot" to click on your target window
  6. target_x = None
  7. target_y = None
  8.  
  9. def send_key(key_combo):
  10. if target_x and target_y:
  11. # THE NUCLEAR SEQUENCE:
  12. # 1. Warp mouse to the saved spot on Emacs
  13. # 2. Click (1) to PHYSICALLY FORCE focus
  14. # 3. Send the key
  15. cmd = f"xdotool mousemove {target_x} {target_y} click 1 key {key_combo}"
  16. subprocess.Popen(cmd, shell=True)
  17. else:
  18. # Fallback
  19. subprocess.Popen(f"xdotool key {key_combo}", shell=True)
  20.  
  21. # --- Draggable Window Logic ---
  22. def start_move(event):
  23. root.x = event.x
  24. root.y = event.y
  25.  
  26. def stop_move(event):
  27. root.x = None
  28. root.y = None
  29.  
  30. def do_move(event):
  31. deltax = event.x - root.x
  32. deltay = event.y - root.y
  33. x = root.winfo_x() + deltax
  34. y = root.winfo_y() + deltay
  35. root.geometry(f"+{x}+{y}")
  36.  
  37. # --- UI Setup ---
  38. root = tk.Tk()
  39. root.title("Keys")
  40. root.geometry("350x120+100+100") # Width x Height + X + Y
  41.  
  42. # REMOVE WINDOW DECORATIONS (The Nuclear Flag)
  43. root.overrideredirect(True)
  44. root.attributes('-topmost', True)
  45.  
  46. # Create a "Handle" to drag the window since we have no title bar
  47. handle = tk.Label(root, text="::: DRAG HERE :::", bg="black", fg="white", cursor="fleur")
  48. handle.pack(fill=tk.X)
  49. handle.bind("<ButtonPress-1>", start_move)
  50. handle.bind("<ButtonRelease-1>", stop_move)
  51. handle.bind("<B1-Motion>", do_move)
  52.  
  53. # Keys Container
  54. frame_keys = tk.Frame(root)
  55. frame_keys.pack(side=tk.TOP, pady=5)
  56.  
  57. btn_config = {'font': ('Arial', 14, 'bold'), 'height': 2, 'width': 5}
  58.  
  59. btn_c = tk.Button(frame_keys, text="^C", command=lambda: send_key("ctrl+c"), **btn_config)
  60. btn_c.pack(side=tk.LEFT, padx=2)
  61.  
  62. btn_d = tk.Button(frame_keys, text="^D", command=lambda: send_key("ctrl+d"), **btn_config)
  63. btn_d.pack(side=tk.LEFT, padx=2)
  64.  
  65. btn_d = tk.Button(frame_keys, text="^X", command=lambda: send_key("ctrl+x"), **btn_config)
  66. btn_d.pack(side=tk.LEFT, padx=2)
  67.  
  68. btn_z = tk.Button(frame_keys, text="^Z", command=lambda: send_key("ctrl+z"), **btn_config)
  69. btn_z.pack(side=tk.LEFT, padx=2)
  70.  
  71. # Quit Button (since we have no 'X' to close)
  72. btn_quit = tk.Button(root, text="x", command=root.quit, bg="red", fg="white", font=("Arial", 8))
  73. btn_quit.place(x=0, y=0)
  74.  
  75. root.mainloop()
  76.  
Advertisement
Add Comment
Please, Sign In to add comment