up vote 0 down vote favorite
share [g+] share [fb]

Is there a way to define a Hotkey conditionally in AutoHotKey? I want to do different keyboard mappings for different machines with different physical keyboards.

This is what I want to do:

RegRead, ComputerName, HKEY_LOCAL_MACHINE, System\CurrentControlSet\Control\ComputerName, ComputerName
If ( ComputerName = BDWELLE-DIM8300 ) 
{
 #Include %A_ScriptDir%\Mappings-BDWELLE-DIM8300.ahk
}

OR

RegRead, ComputerName, HKEY_LOCAL_MACHINE, System\CurrentControlSet\Control\ComputerName, ComputerName
If ( ComputerName = BDWELLE-DIM8300 ) 
{
 LWin::LAlt
    [more hotkey definitions that only apply to this machine]
}

but since AHK parses Hotkey definitions and #Include statements BEFORE interpreting If statements, the Hotkeys definitions (whether buried in an #Include or not) do not respect the If condition.

Thanks for pointing me to AutoHotKey_L!

Do you have a specific example of how to conditionally define a hotkey? The syntax is very confusing. Here's what I'm trying (after having installed AutoHotKey_L.exe in place of AutoHotKey.exe):

RegRead, ComputerName, HKEY_LOCAL_MACHINE, System\CurrentControlSet\Control\ComputerName, ComputerName 
#If ( ComputerName = BDWELLE-DIM8300 ) 
LWin::LAlt

but that doesn't seem to work...

link|improve this question
feedback

3 Answers

Lifehacker presented an AHK script called AutoInclude that help you select which scripts to use on different computers. It accomplishes this by textually concatenating scripts into one file and then running that one file.

Disclaimer: I have not used it.

link|improve this answer
feedback

You may want to give Autohotkey L a shot. Among other things, it has a #If statement, which works just like #IfWinActive, but for arbitrary code.

link|improve this answer
Thanks for pointing me to AutoHotKey_L! Do you have a specific example of how to conditionally define a hotkey? The syntax is very confusing. Here's what I'm trying (after having installed AutoHotKey_L.exe in place of AutoHotKey.exe): RegRead, ComputerName, HKEY_LOCAL_MACHINE, System\CurrentControlSet\Control\ComputerName, ComputerName #If ( ComputerName = BDWELLE-DIM8300 ) LWin::LAlt but that doesn't seem to work... – Bowen Dec 18 '09 at 17:43
I think you have to end it with another #if, like #IfWinActive, but I've never actually used AHKL, sorry :( – Phoshi Dec 18 '09 at 18:25
feedback

Look at the Hotkey command - it can create or modify HKs dynamically anywhere in a script.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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