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.

In Windows (XP, 7, 8) how do you quickly assign keyboard shortcuts to launch your favorite applications using autohotkey when the application is active.

In Keyboard utilities, you can launch your favorite applications for fast access, by simply pressing a hotkey.

I was wandering if that could be done using autohotkey as well.

Edited:

Normally to add a script that when Ctrl+Alt+N is pressed, Notepad will be launched. You would need to have the following script.

^!n:: Run Notepad

What I want is that when the application is active, pressing Ctrl + Shift + A should take the path where the application is installed and create a script like above.

So when Command Prompt is active, pressing Ctrl + Shift + A should create a script like the following.

^!t:: Run C:\WINDOWS\system32\cmd.exe

where C:\WINDOWS\system32\cmd.exe is the path where cmd is installed/located

and Ctrl + Shift + T is the keyboard shortcut.

share|improve this question
    
Yes, it is windows (XP, 7, 8) –  Ishan Dec 27 '12 at 22:37
    
Added it to the question ;) –  Everett Dec 27 '12 at 23:01
add comment

2 Answers

Yes, you can. The following example will launch explorer when Win+0 is pressed (# denotes the Window key in AHK):

#0::Run C:\Windows\System32\explorer.exe

If the application does not launch because it is already running, you could create a batch file containing:

start program.exe

And tell the AHK script to launch that batch file.

share|improve this answer
    
I already knew how to do that but this is not what I am after. Your solution requires to actually find the application path and then create a keyboard shortcuts from it. Please have a look at the youtube.com/watch?v=GzcQbrkdvJU&feature=player_embedded to illustrate what I am after but using autohotkey instead of PhraseExpander which the video uses. –  Ishan Dec 27 '12 at 3:35
    
So you're after a GUI to create shortcut assignments? –  Suchipi Dec 27 '12 at 20:38
add comment

This isn't something you can do easily.

You could do something like: http://stackoverflow.com/questions/12851677/dynamically-create-autohotkey-hotkey-to-function-subroutine

Or you could modify your file at runtime and reload it.

#SingleInstance Force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^!n::
    WinGet, pn, ProcessName, A
    path := GetProcessPath(pn)
    tooltip, press a new hotkey
    Input, new_hotkey, L1
    tooltip,

    code = ^!%new_hotkey%`:`:Run, %path%`n
    FileAppend, %code%, %A_ScriptFullPath%

    Reload
    Sleep 1000 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
    MsgBox, 4,, The script could not be reloaded. Would you like to open it for editing?
    IfMsgBox, Yes, Edit
    return


GetProcessPath(exe) {
    ;;http://www.autohotkey.com/board/topic/32965-getting-file-path-of-a-running-process/
    for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where name ='" exe "'")
        return process.ExecutablePath
}

return

Hotkeys:
^!f::Run, C:\Program Files\Mozilla Firefox\firefox.exe
share|improve this answer
add comment

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.