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.

Revisions

  1. @liberize liberize revised this gist Aug 16, 2025. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions powertoys.ahk
    Original file line number Diff line number Diff line change
    @@ -53,7 +53,7 @@ PowerToysRunWithInput(str) {
    ; Use ctrl+shift+d to call PowerTranslator plugin
    ; Select text then press ctrl+shift+d, the selected text will be translated
    ^+D:: {
    Send("^c")
    Send("^c") ; use SendEvent if not working
    ClipWait(0.5)
    PowerToysRunWithInput("| ")
    }
    @@ -73,7 +73,7 @@ Escape:: {
    ; Use ctrl+shift+r to call PowerTranslator plugin
    ; Select text then press ctrl+shift+r, the selected text will be translated
    ^+R:: {
    Send("^c")
    Send("^c") ; use SendEvent if not working
    ClipWait(0.5)
    Send("^+t") ; set PowerTranslator hotkey to ctrl+shift+t in cmdpal settings
    WinWaitActive("命令面板") ; cmdpal window title, adapt to your language
  2. @liberize liberize revised this gist Aug 15, 2025. 1 changed file with 29 additions and 5 deletions.
    34 changes: 29 additions & 5 deletions powertoys.ahk
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,8 @@ SendMode("Input")
    SetWorkingDir(A_ScriptDir)

    ; -----------------------------------------------------------------------
    ; 1. Use only space key to call out PowerToys Peek
    ; 1. PowerToys Peek
    ; Use only space key to trigger PowerToys Peek
    ; Credit: https://github.com/deanmongel/use-space-in-peek-of-powertoys

    GuiWindowHwnd := 0
    @@ -26,15 +27,15 @@ space:: {
    }
    #HotIf

    ; press space key or esc to close peek
    ; 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
    ; 2. PowerToys Run

    PowerToysRunWithInput(str) {
    Send("!{Space}")
    @@ -44,15 +45,38 @@ PowerToysRunWithInput(str) {
    PostMessage(WM_CHAR:=0x102, ord(A_LoopField),, ctl)
    }

    ; Example 1: use ctrl+shift+c to call ClipboardManager plugin
    ; Use ctrl+shift+c to call ClipboardManager plugin
    ^+C:: {
    PowerToysRunWithInput("c: ")
    }

    ; Example 2: use ctrl+shift+d to call PowerTranslator plugin
    ; 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")
    }

  3. @liberize liberize revised this gist Dec 19, 2024. No changes.
  4. @liberize liberize revised this gist Dec 19, 2024. No changes.
  5. @liberize liberize revised this gist Dec 19, 2024. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions powertoys.ahk
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #NoTrayIcon

    SendMode("Input") ; 推荐用于新脚本,因为它具有更快的速度和更高的可靠性。
    SetWorkingDir(A_ScriptDir) ; 确保一致的工作目录。
    SendMode("Input")
    SetWorkingDir(A_ScriptDir)

    ; -----------------------------------------------------------------------
    ; 1. Use only space key to call out PowerToys Peek
    @@ -10,15 +10,14 @@ SetWorkingDir(A_ScriptDir) ; 确保一致的工作目录。
    GuiWindowHwnd := 0

    GetFocusedControlClassNN() {
    GuiWindowHwnd := WinExist("A") ; 将当前活动窗口的句柄ID存储在变量GuiWindowHwnd中
    FocusedControl := ControlGetClassNN(ControlGetFocus("ahk_id " GuiWindowHwnd)) ; 从上面的窗口中获取当前聚焦控件的ClassNN,并将其存储在FocusedControl变量中
    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 {
    @@ -27,7 +26,7 @@ space:: {
    }
    #HotIf

    ; 按空格键再次关闭Peek UI
    ; press space key or esc to close peek
    #HotIf WinActive("ahk_exe PowerToys.Peek.UI.exe")
    space::Send("!{F4}")
    esc::Send("!{F4}")
    @@ -51,6 +50,7 @@ PowerToysRunWithInput(str) {
    }

    ; 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)
  6. @liberize liberize created this gist Dec 19, 2024.
    58 changes: 58 additions & 0 deletions powertoys.ahk
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    #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("| ")
    }