0

Is it possible to register shortcuts on Windows 7 so that regardless where you are looking (Desktop, a folder etc) the shortcut gets "heard" and the appropriate action is performed.

For example, creating a shortcut in the System32 folder which will work if you use Run with the shortcut's name, will not work if you set a key combination when focus is set on the Desktop for example.

Is there a native way of registering top-level shortcuts or even an application for enabling this?

Example of things I want keyboard shortcuts for:

  • open a specific folder like %path%
  • create a new .js file in the current folder
  • launch an application eventually with its path set to the current location if the app supports this (e.g. command prompt)

Thank you.

Francisc
  • 1,167

1 Answers1

1

You could probably do this with AutoHotKey.

For instance, let's say you want the shortcut Win + S to launch MyScript. Install AutoHotKey, copy what follows to the AutoHotkey.ahk file, and restart 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:\ "
    }
}

Inspired from those two answers:

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