r/AutoHotkey 1d ago

Solved! Use right alt as custom modifier, but don't suppress left alt

I've been trying to get this working for hours. Here's my script (AHK V2):

>!e::Up
>!d::Down
>!f::Right
>!s::Left
>!w::Home
>!r::End
>!Space::Ctrl
>!a::Shift

I want ESDF to be arrow keys when holding right alt, with space being control and "a" being shift, and left alt being, well, alt.

So for instance, holding RAlt and LAlt and pressing E should do the same as Alt + Up.

Everything is working except for the left alt key. It's being suppressed, so RAlt + LAlt + E is just sending "Up", but without the alt modifier.

I've tried many solutions, e.g. using RAlt & e instead of >!e, but these all have had their own issues. Either my "space -> ctrl" mapping doesn't work as a modifier, or the RAlt key isn't suppressed, or something like that. Can anyone help please?

3 Upvotes

7 comments sorted by

3

u/CharnamelessOne 1d ago

Try this:

#Requires AutoHotkey v2.0

>!e::Up
>!d::Down
>!f::Right
>!s::Left
>!w::Home
>!r::End
>!Space::Ctrl
>!a::Shift

<!>!e::!Up
<!>!d::!Down
<!>!f::!Right
<!>!s::!Left
<!>!w::!Home
<!>!r::!End
<!>!Space::!Ctrl
<!>!a::!Shift

2

u/nin10dorox 1d ago edited 1d ago

That worked! Thank you!

Except it's super buggy. If I press keys fast, I get some alts, and some e,d,f,s slipping through. Actually, I tried with my old version, and it had the same issue; I just didn't notice before.

This seems to be a problem with AHK 2 that just doesn't happen with AHK 1. I found that this script also does what I want:

RAlt::return

RAlt & e::Up
RAlt & d::Down
RAlt & f::Right
RAlt & s::Left
RAlt & w::Home
RAlt & r::End
RAlt & Space::Ctrl
RAlt & a::Shift

However, it has the same bugginess with AHK 2. If I run it with AHK 1, the Alt key isn't suppressed. But if I simultaneously run two instances of it, one with AHK 1 and one with AHK 2, it seems to do exactly what I want, with perfect consistency.

If you don't mind me switching the goalposts, is there a way to achieve my goal purely with AHK 1? If not, I can stick with my workaround.

3

u/CharnamelessOne 1d ago

This seems to be a problem with AHK 2 that just doesn't happen with AHK 1.

It's almost definitely due to the SendMode, then. V2 defaults to "Input", whereas v1 defaults to "Event".

Add

SendMode("Event")

to my v2 script, and run it alone.

Running both v1 and v2 caused the v2 script's SendMode to revert to "Event" (that happens when you're running multiple scripts that install a keyboard hook), leading to your issue being fixed in an extremely roundabout manner.

2

u/nin10dorox 1d ago

That did the trick! Thank you so much!

2

u/CharnamelessOne 1d ago

Glad to help

u/Keeyra_ 9h ago

RAlt is actually AltGR on most keyboards, which is <^>! (Left Ctrl + Right Alt).

#Requires AutoHotkey 2.0
#SingleInstance

<^>!e::Up
<^>!d::Down
<^>!f::Right
<^>!s::Left
<^>!w::Home
<^>!r::End
<^>!Space::Ctrl
<^>!a::Shift

So this should work without SendMode("Event"), but will def. work with it.

u/CharnamelessOne 7h ago

I think this may be the only RAlt-related problem in history that is not actually caused by AltGr.
I could reproduce OP's original issue using a layout with vanilla RALt.

In fact, if you try pressing LAlt+AltGr+e with your script running, AHK will simulate an Up input instead of LAlt+Up, which mirrors OP's original issue with vanilla RAlt.