What's the easiest way to make a hotkey for windows?

Eugene picture Eugene · Jun 10, 2009 · Viewed 25.6k times · Source

For example , you push Ctrl+V and insert the buffer content into the window. How can I create my own hotkeys like that? Sorry for noobish question.

Answer

Copas picture Copas · Jun 10, 2009

A great way to do this quickly and easily is with a script language that focuses on macro programming. My favorite is AutoIt as it says in a clip from the AutoIt help file...

AutoIt was initially designed for PC "roll out" situations to reliably automate and configure thousands of PCs. Over time it has become a powerful language that supports complex expressions, user functions, loops and everything else that veteran scripters would expect.

Writing a hotkey application in AutoIt couldn't be easier. For example lets say for some reason (to obscure to mention) you would like Alt+Q to react as number pad key 7 in a particular situation possibly so you don't have to reach across the keyboard for it. Here's some code that does that...

Func _num7()
    Send("{numpad7}")
EndFunc

HotKeySet("!{q}","_num7")

While 1
    sleep(10)
WEnd

If that's not straight forward enough the AutoIt help file and forums are very helpful. Not to mention a (very) few AutoIt developers are available on SO if you end up with any AutoIt specific questions.

In the example above lets say you only wanted the hotkeys to be active when a particular application was in use so as to not interfere with other hotkeys. This code would accomplish just that.

; The comment character in AutoIt is ;
Local $inTargetProg = False

Func _num7()
    Send("{numpad7}")
EndFunc

While 1
    If WinActive("Target Application Window Title") and Not $inTargetProg Then
        HotKeySet("!{q}","_num7") ; binds Alt+Q to the _num7() function
        $inWC3 = True
    EndIf

    If Not WinActive("Target Application Window Title") and $inTargetProg Then
        HotKeySet("!{q}") ; UnBind the hotkey when not in use
        $inWC3 = False
    EndIf

    sleep(5)
WEnd