Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import subprocess
- import time
- # Store the "safe spot" to click on your target window
- target_x = None
- target_y = None
- def send_key(key_combo):
- if target_x and target_y:
- # THE NUCLEAR SEQUENCE:
- # 1. Warp mouse to the saved spot on Emacs
- # 2. Click (1) to PHYSICALLY FORCE focus
- # 3. Send the key
- cmd = f"xdotool mousemove {target_x} {target_y} click 1 key {key_combo}"
- subprocess.Popen(cmd, shell=True)
- else:
- # Fallback
- subprocess.Popen(f"xdotool key {key_combo}", shell=True)
- # --- Draggable Window Logic ---
- def start_move(event):
- root.x = event.x
- root.y = event.y
- def stop_move(event):
- root.x = None
- root.y = None
- def do_move(event):
- deltax = event.x - root.x
- deltay = event.y - root.y
- x = root.winfo_x() + deltax
- y = root.winfo_y() + deltay
- root.geometry(f"+{x}+{y}")
- # --- UI Setup ---
- root = tk.Tk()
- root.title("Keys")
- root.geometry("350x120+100+100") # Width x Height + X + Y
- # REMOVE WINDOW DECORATIONS (The Nuclear Flag)
- root.overrideredirect(True)
- root.attributes('-topmost', True)
- # Create a "Handle" to drag the window since we have no title bar
- handle = tk.Label(root, text="::: DRAG HERE :::", bg="black", fg="white", cursor="fleur")
- handle.pack(fill=tk.X)
- handle.bind("<ButtonPress-1>", start_move)
- handle.bind("<ButtonRelease-1>", stop_move)
- handle.bind("<B1-Motion>", do_move)
- # Keys Container
- frame_keys = tk.Frame(root)
- frame_keys.pack(side=tk.TOP, pady=5)
- btn_config = {'font': ('Arial', 14, 'bold'), 'height': 2, 'width': 5}
- btn_c = tk.Button(frame_keys, text="^C", command=lambda: send_key("ctrl+c"), **btn_config)
- btn_c.pack(side=tk.LEFT, padx=2)
- btn_d = tk.Button(frame_keys, text="^D", command=lambda: send_key("ctrl+d"), **btn_config)
- btn_d.pack(side=tk.LEFT, padx=2)
- btn_d = tk.Button(frame_keys, text="^X", command=lambda: send_key("ctrl+x"), **btn_config)
- btn_d.pack(side=tk.LEFT, padx=2)
- btn_z = tk.Button(frame_keys, text="^Z", command=lambda: send_key("ctrl+z"), **btn_config)
- btn_z.pack(side=tk.LEFT, padx=2)
- # Quit Button (since we have no 'X' to close)
- btn_quit = tk.Button(root, text="x", command=root.quit, bg="red", fg="white", font=("Arial", 8))
- btn_quit.place(x=0, y=0)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment