透過捷徑在 Windows 上啟動應用程式或執行命令

透過捷徑在 Windows 上啟動應用程式或執行命令

是否可以在 Windows 7 上註冊快捷方式,以便無論您在哪裡(桌面、資料夾等)查看快捷方式,都會「聽到」快捷方式並執行適當的操作。

例如,在System32 資料夾中建立一個快捷方式,如果您使用「運行」和快捷方式的名稱,該快捷方式將起作用,但如果您在桌面上設定焦點時設定組合鍵,則該快捷方式將不起作用。

是否有註冊頂級快捷方式的本機方法,甚至有用於啟用此功能的應用程式?

我想要鍵盤快捷鍵的範例:

  • 開啟特定資料夾,例如 %path%
  • 在目前資料夾中建立一個新的 .js 文件
  • 如果應用程式支援此功能(例如命令提示字元),則最終啟動應用程式並將其路徑設為目前位置

謝謝。

答案1

你可能可以這樣做自動熱鍵

例如,假設您希望使用快捷方式Win+S來啟動MyScript。安裝 AutoHotKey,將以下內容複製到 AutoHotkey.ahk 檔案中,然後重新啟動 AutoHotKey:

SetTitleMatchMode RegEx
return

; Stuff to do when Windows Explorer is open
;
#IfWinActive ahk_class ExploreWClass|CabinetWClass

    #s::
        LaunchMyScriptInCurrent()
    return
#IfWinActive


; Launches a custom script in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
LaunchMyScriptInCurrent()
{
    ; This is required to get the full path of the file from the address bar
    WinGetText, full_path, A

    ; Split on newline (`n)
    StringSplit, word_array, full_path, `n
    ; Take the first element from the array
    full_path = %word_array1%   

    ; strip to bare address
    full_path := RegExReplace(full_path, "^Address: ", "")

    ; Just in case - remove all carriage returns (`r)
    StringReplace, full_path, full_path, `r, , all

    IfInString full_path, \
    {
        Run, C:\Path\To\MyScript "%full_path%"
    }
    else
    {
        Run, C:\Path\To\MyScript "C:\ "
    }
}

受到這兩個答案的啟發:

  1. https://superuser.com/a/205368/118346
  2. https://stackoverflow.com/a/100648/1005455

相關內容