Skip to content

Instantly share code, notes, and snippets.

@pa-0
Forked from liberize/powertoys.ahk
Created October 2, 2025 00:25
Show Gist options
  • Save pa-0/a21f60461efd4625b2b07afcd13ff848 to your computer and use it in GitHub Desktop.
Save pa-0/a21f60461efd4625b2b07afcd13ff848 to your computer and use it in GitHub Desktop.
AutoHotKey2 helper script for PowerToys
#NoTrayIcon
SendMode("Input")
SetWorkingDir(A_ScriptDir)
; -----------------------------------------------------------------------
; 1. PowerToys Peek
; Use only space key to trigger PowerToys Peek
; Credit: https://github.com/deanmongel/use-space-in-peek-of-powertoys
GuiWindowHwnd := 0
GetFocusedControlClassNN() {
GuiWindowHwnd := WinExist("A")
FocusedControl := ControlGetClassNN(ControlGetFocus("ahk_id " GuiWindowHwnd))
return FocusedControl
}
#HotIf WinActive("ahk_exe explorer.exe")
space:: {
classnn := GetFocusedControlClassNN()
if (!RegExMatch(classnn, "Microsoft\.UI\.Content\.DesktopChildSiteBridge.*") && !RegExMatch(classnn, "Edit.*")) {
Send("+{Space}")
} else {
Send("{Space}")
}
}
#HotIf
; Press space key or esc to close peek
#HotIf WinActive("ahk_exe PowerToys.Peek.UI.exe")
space::Send("!{F4}")
esc::Send("!{F4}")
#HotIf
; -----------------------------------------------------------------------
; 2. PowerToys Run
PowerToysRunWithInput(str) {
Send("!{Space}")
WinWaitActive("PowerToys.PowerLauncher")
ctl := (ControlGetFocus() || WinGetID())
loop parse, str
PostMessage(WM_CHAR:=0x102, ord(A_LoopField),, ctl)
}
; Use ctrl+shift+c to call ClipboardManager plugin
^+C:: {
PowerToysRunWithInput("c: ")
}
; Use ctrl+shift+d to call PowerTranslator plugin
; Select text then press ctrl+shift+d, the selected text will be translated
^+D:: {
Send("^c")
ClipWait(0.5)
PowerToysRunWithInput("| ")
}
; -----------------------------------------------------------------------
; 3. PowerToys Command Palette
; Press esc key once to dismiss Command Palette
#HotIf WinActive("命令面板") ; cmdpal window title, adapt to your language
Escape:: {
Send("{Esc}")
Send("{Esc}")
Send("{Esc}")
}
#HotIf
; Use ctrl+shift+r to call PowerTranslator plugin
; Select text then press ctrl+shift+r, the selected text will be translated
^+R:: {
Send("^c")
ClipWait(0.5)
Send("^+t") ; set PowerTranslator hotkey to ctrl+shift+t in cmdpal settings
WinWaitActive("命令面板") ; cmdpal window title, adapt to your language
Send("^v")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment