LCtrl key stuck when using AltGr in a hotkey Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MaEstRo
Posts: 5
Joined: 21 Oct 2018, 10:22

LCtrl key stuck when using AltGr in a hotkey

21 Oct 2018, 12:17

Hello everyone. Thank you all for making such a great software and such a friendly documentation and forum.
I've been trying to remap an English standard QWERTY layout to a Colemak layout with lots of custom hotkeys for programming.
Most of the remappings have worked fine. The ones that include AltGr as part of a hotkey, however, seem to leave the LCtrl key down after they are used.

Here's an example of the problem:

Lets say I want the keys (e f d s) to behave like the directional arrow keys (Up Right Down Left) respectively while the AltGr key is pressed down.
This is the script I'm using to get that behavior:

Code: Select all

#NoEnv
#Warn
SendMode Input

<^>!e::Send, {Up}
<^>!f::Send, {Right}
<^>!d::Send, {Down}
<^>!s::Send, {Left}
The hotkeys work as intended and I can us e, f, d, s while pressing AltGr as the directional arrows, but once I release AltGr the LCtrl key is left in the down state.

This is the key history given by the script after pressing the AltGr + e and releasing everything.

VK SC Type Up/Dn Elapsed Key
--------------------------------------------------
A2 01D d 8.59 LControl
A5 138 d 0.00 RAlt
45 012 h d 0.27 e
A5 138 i u 0.00 RAlt
A2 01D i u 0.00 LControl
26 148 i d 0.00 Up
26 148 i u 0.00 Up
A5 138 i d 0.00 RAlt
A2 01D i d 0.00 LControl ←
45 012 s u 0.16 e
A5 138 u 0.06 RAlt


The third from last line shows the problem, the last instruction for LControl is down, there should be a corresponding LControl up instruction as the last line in this history.
I have tried changing the SendMode declaration at the top of the page to every other alternative (Event, InputThenPlay, Play) and it didn't help, actually in that case the letters stop working as directional arrows.
I tried adding a {LControl Up} to the commands that are triggered by the hotkeys but this LControl instruction gets inserted in the key history after the Up instructions and before the LControl down instruction that its creating the problem. Basically this two lines get inserted in the previous key history

...idem
26 148 i d 0.00 Up
26 148 i u 0.00 Up
A2 01D i d 0.00 LControl ←
A2 01D i u 0.00 LControl ←

...idem

So the problem remains...

I would greatly appreciate any suggestions about how to prevent the LCtrl key from getting stuck in this scenario, it seems I just need to get that LControl Up instruction in the right place, but it has proven tricky. It is the last piece of the puzzle to have what I consider the perfectly customized keyboard for programming.
If I new the exact instruction that the interpreter is expanding this code <^>!e::Send, {Up} into I would be able to write a function that mimics that behavior inserting the LControl Up instruction where It seems to be missing. Then calling the function with the hotkey would get me what I want.
Thanks for any pointers. The forum has many references to LCtrl getting stuck after using AltGr but none of the ones I found seem to solve my issue or perhaps I'm not experienced enough to make use of them. I don't mind working on my own if you think you can point me to the right part of the documentation or to another post that solves the problem and tell me off for not looking close enough that is fine too and I may very well deserve it.
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: LCtrl key stuck when using AltGr in a hotkey

21 Oct 2018, 16:17

Hi and welcome,

I'm not entirely sure why you have this problem, but maybe you can try it out with my script:

Code: Select all

^!e::
Send {Up}
return

^!f::
Send {Right}
return

^!d::
Send {Down}
return

^!s::
Send {Left}
return
I tested it several times and didn't face any problems.
Even though I use a German keyboard layout, I'm pretty sure it should work for you as well.
Check it out and let us know!

P.S. About your other commands in your script: I never use them - but try it out with and without them, too.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
MaEstRo
Posts: 5
Joined: 21 Oct 2018, 10:22

Re: LCtrl key stuck when using AltGr in a hotkey

22 Oct 2018, 00:14

Thank you for the quick reply Scr1pter. I have been reading the docs and experimenting for hours and haven't been able to make the script work using AltGr. I have taken a similar approach to your suggestion and used a different key, I have chosen to use LAlt instead of AltGr in my script and everything works just fine. I still want to understand why it doesn't work with AltGr because it would be more comfortable to use that key. I now have a fully working remaping of my keyboard. for anyone interested in a working custoumizable annotated script that remaps a QWERTY keyboard to a Colemak keyboard with convenient hotkeys for programming work. This is the result of my work...
qwerty_2_Colemak.ahk
Script remap of a qwerty keyboard layout to a Colemak keyboard layout
(14.36 KiB) Downloaded 29 times
...I hope it helps someone...

For anyone intrested in Colemak layuts out there:
If you know about AutoHotkey and find a way to use AltGr instead of the LAlt for the third keyboard layer in the script above, or you can find it in your heart to simplify and improve this script, please let us know at the forums of AutoHotkey. I have been using Colemak for general typing and programming for a while and know that a good customizable Colemak layout is sorely needed by Colemak enthusiast on the web. I don't know much about AutoHotkey and had to read the docs for 3 days to produce this script. Although it is far better than anything else I have found (including more rigid layouts produced by Microsoft Keyboard Layout Manager) I know it has room for much improvement, I just don't know enough to improve it anymore myself, perhaps you can take it from here. If you do, or you know about a better Colemak keyboard layout alternative, please let us know at the forums thread Colemak Layout Remappings Using AutoHotkey.
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: LCtrl key stuck when using AltGr in a hotkey

22 Oct 2018, 15:06

Hello,

My script uses Left Ctrl + Left Alt which is the same as Right Alt (Alt Gr).
I didn't actually press left ctrl + left alt.
I pressed Alt Gr and it worked.

Normally it should work for you as well.
I can't tell you why your original script does not work.
However, since the end result is the same, does is really matter?

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
MaEstRo
Posts: 5
Joined: 21 Oct 2018, 10:22

Re: LCtrl key stuck when using AltGr in a hotkey  Topic is solved

23 Oct 2018, 21:31

Thank you Scr1pter!. I tried your suggestion again after your second explanation, I removed the SendMode Input option that I was using but you weren't and used your suggested hotkey ^!. That solved the problem of the LCtrl key getting stuck after triggering the hotkey with AltGr, a big step forward...

Unfortunately when I use your Ctrl + Alt hotkey ^! to capture the AltGr key presses (e.g. ^!e::Send, {Up}), I find that I have to press AltGr once every time I want to send a directional key press.
I wanted instead to be able to keep AltGr pressed and then navigate with as many consecutive key presses as desired with the keys e s d f as if they were {Up} {Left} {Down} {Right}.

However, you got me thinking that I hadn't tried to capture the AltGr presses using other alternatives to the ones suggested by you (^!) or the documentation (<^>!). After a bit of experimentation, sure enough, I found one that works exactly as I had described, the idea is simple: every time you press AltGr two key presses are sent to the screen LCtrl and RAlt, so instead of trying to capture them both, I capture one and ask AutoHotkey to ignore the other with the * option...this is the solution:


"capture AltGr presses with the hotkey (*!>) which captures the RAlt and ignores the LCtrl"


That way I have been able to use AltGr as a modifier key for many hotkeys without Ctrl getting stuck or having to press AltGr multiple times for multiple consecutive target keys. Scr1pter, thank you so much for your help! this would be the original example script using AltGr as modifier:

Code: Select all

;SendMode Input

*!>e::Send, {Up}
*!>f::Send, {Right}
*!>d::Send, {Down}
*!>s::Send, {Left}

And this would be the improved and expanded QWERTY to Colemak layout that uses that technique above and has a ton of useful hotkeys for programming work in Python, HTML, CSS, JavaScript, AutoHotkey and any other language with similar syntax to those. This scrip is now much closer to what I originally wanted. Now we just need someone to make the script more friendly by creating a UI that allows customization and better visualization of the key remappings and this could very well be, the most versatile Colemak layout I have ever heard of.

qwerty_2_Colemak.ahk
Script that remaps a QWERTY keyboard to a Colemak keyboard with lots of useful hotkeys for programming work.
(16.08 KiB) Downloaded 38 times

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jeves and 278 guests