lal12 / macroMyKBD

macroMyKBD
MIT License
51 stars 7 forks source link

macroMyKBD work with AutoHotKey? #8

Closed PotatoJet closed 4 years ago

PotatoJet commented 4 years ago

@KGT1 @lal12 #1 Thank you for your video tutorial.It works! But how to integrate all key's AHK script into one AHK script? I don't want A.ahk B.ahk C.ahk... I want just one script like this↓↓↓

A::msgbox, KGT1 is good man

B::msgbox, lal12 is genius

C::msgbox, I'm superman

I really appreciate it. If there's no way, it's OK.

lal12 commented 4 years ago

Yes you can. How depends a little bit on what you want to do, but the easiest way to just look for a single key event is this:

EnvGet, evtKeyCodes, EVENT_KEYS

switch evtKeyCodes
{
case "4":
    MsgBox, You have pressed A
    return
case "5":
    MsgBox, You have pressed B
    return
case "6":
    MsgBox, You have pressed C
    return
default:
    MsgBox, A not handled keyCode "%evtKeyCodes%" was received
}

This can work for multiple keys too, but needs a bit more code in the AHK script.

Though I am not really familiar around AHK scripting, nor can I currently test this, so it might need a bit of tweaking.

A bit of explanation what it does: EnvGet, evtKeyCodes, EVENT_KEYS reads a so called environment variable EVENT_KEYS which is passed from macroMyKBD and puts it into the local variable evtKeyCodes;

switch evtKeyCodes "look into the variable and jump to the matching case statement, if there is no matching case jump to default instead".

PotatoJet commented 4 years ago

Thank you for your reply. I will have a try.