ショートカットを使用して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:\ "
    }
}

これら 2 つの回答からインスピレーションを得て:

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

関連情報