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. Use only space key to call out PowerToys Peek
; Credit: https://github.com/deanmongel/use-space-in-peek-of-powertoys
GuiWindowHwnd := 0
GetFocusedControlClassNN() {
GuiWindowHwnd := WinExist("A") ; 将当前活动窗口的句柄ID存储在变量GuiWindowHwnd中
FocusedControl := ControlGetClassNN(ControlGetFocus("ahk_id " GuiWindowHwnd)) ; 从上面的窗口中获取当前聚焦控件的ClassNN,并将其存储在FocusedControl变量中
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
; 按空格键再次关闭Peek UI
#HotIf WinActive("ahk_exe PowerToys.Peek.UI.exe")
space::Send("!{F4}")
esc::Send("!{F4}")
#HotIf
; -----------------------------------------------------------------------
; 2. Use hotkey to call out specific PowerToys Run plugin
PowerToysRunWithInput(str) {
Send("!{Space}")
WinWaitActive("PowerToys.PowerLauncher")
ctl := (ControlGetFocus() || WinGetID())
loop parse, str
PostMessage(WM_CHAR:=0x102, ord(A_LoopField),, ctl)
}
; Example 1: use ctrl+shift+c to call ClipboardManager plugin
^+C:: {
PowerToysRunWithInput("c: ")
}
; Example 2: use ctrl+shift+d to call PowerTranslator plugin
^+D:: {
Send("^c")
ClipWait(0.5)
PowerToysRunWithInput("| ")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment