1
votes

I want to remap alt+e when caps is on in autocad.

And when capslock is not on, alt+e should open menu edit.

I use script like this

<!e::
if(GetKeyState( "CAPSLOCK", "T" ))
{
    SendInput erase{space}wp{space}
}
else
{
    Send !e
}

When I turn on capslock, remap key is OK.

When I turn off capslockand alt+e, menu edit opened, but closed immediately.

Thanks.

2
I want to post question at autohotkey community. But it always give me error: You have provided an invalid answer to the question.coordinate

2 Answers

2
votes

You will want a $ at the beginning of your hotkey to prevent the endless loop that the !e in your else block will trigger. You will also want to add a Return at the end of the hotkey to prevent the script from continuing into what is below this hotkey.

$!e::
if GetKeyState( "CapsLock", "T" )
    Sendinput, erase{space}wp{space}
else
    Sendinput, !e
Return

(Brackets are only required when if/else blocks are more than one line.)

Beyond that, the likely issue is that it's an alt hotkey that is also set to send alt.
I say this is an issue because if you press and hold alt, it activates menus,
and then the script sends alt, which will be in conflict with that.
As Ricardo said, the ideal way to script this is with the #IF command (only included with AHK_L).

#If GetKeyState("CapsLock", "T") and WinActive("AutoCAD")

!e:: SendInput, erase{space}wp{space}

#If

Notice that you can add the WinActive() function to the #If command's expression. Try it without that first, and also realize that the application's title needs to be exactly "AutoCAD" at all times for that to work. I would recommend finding AutoCad's ahk_class, with AHK's window spy, instead of using the title.

If it still does not work, it is likely that AHK is sending faster than AutoCAD would like to receive.
Info on how to deal with that can be found here.

1
votes

Try to change your else block to this:

Send, {ALTDOWN}e{ALTUP}

I do not rely on these symbols to send keystrokes in AutoHotKey.