Last active
December 19, 2024 09:38
-
-
Save liberize/c083a0bd6f5c39c28879c5e0f892b74f to your computer and use it in GitHub Desktop.
AutoHotKey2 helper script for PowerToys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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") | |
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. 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 | |
; Select text then press ctrl+shift+d, the selected text will be translated | |
^+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
shell:startup
in address bar to open Startup folder.