Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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. http://superuser.com/a/205368/118346
  2. http://stackoverflow.com/a/100648/1005455
share|improve this answer
    
Thanks for that. I take it there's no simple way to do this, eventually with a GUI? Editing scripts is better than nothing, but I don't want to waste time learning how to do that when a GUI would be so much faster. –  Francisc Sep 24 '12 at 13:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.