Remapping Alt key is unreliable
Posted: 07 Sep 2023, 11:43
I use the following script with RAlt as a dead key to type accented letters on a US keyboard. This works, but often, especially when typing fast, in Windows Notepad, the menu is opened. So it seems the Alt key event masking fails sometimes.
If this occurs, the log of the script shows some ignored (i) events of the A_MenuMaskKey and RAlt, which seems unusual.
What is also strange, the script works much more reliable if a second script has a keyboard hook installed, e.g. if the following script is run concurrently, the problem almost never happens:
I would rather accept a certain delay in typing than the current, unreliable, behaviour.
Also, SendMode "Event" did not solve the problem.
Code: Select all
#Requires AutoHotkey v2.0.7+
#Warn All
KeyHistory 500
#SingleInstance Force
Persistent
A_MaxHotkeysPerInterval := 200
;SendMode "Event"
A_MenuMaskKey := "vkE8"
Umlaut := 0
return
#UseHook
#HotIf (Umlaut == 1)
o::
{
global Umlaut
SendText "ö"
Umlaut := 0
}
u::
{
global Umlaut
SendText "ü"
Umlaut := 0
}
#HotIf
RAlt::
{
global Umlaut
Umlaut := 1
}
~*Esc:: ExitApp
Code: Select all
VK SC Type Up/Dn Elapsed Key Window
-------------------------------------------------------------------------------------------------------------
...
A5 138 h d 0.09 RAlt
4F 018 h d 0.02 o
4F 018 s u 0.09 o
55 016 u 0.00 u
A5 138 s u 0.01 RAlt
A5 138 h d 0.06 RAlt
55 016 h d 0.01 u
4F 018 h d 0.00 o
55 016 s u 0.52 u
E7 00FC U d 0.00 ü
E8 000 i d 0.00 not found
E8 000 i u 0.00 not found
A5 138 i u 0.00 RAlt
E8 000 i d 0.00 not found
A5 138 i d 0.00 RAlt
E8 000 i u 0.00 not found
55 016 u 0.06 u
4F 018 s u 0.00 o
A5 138 s u 0.02 RAlt
A5 138 h d 0.08 RAlt
4F 018 d 0.00 o
55 016 d 0.02 u
4F 018 u 0.08 o
55 016 u 0.02 u
A5 138 s u 0.01 RAlt
...
Code: Select all
#Requires AutoHotkey v2.0.7+
KeyHistory 500
#SingleInstance force
#Warn All
InstallKeybdHook
#UseHook
Persistent
~*Esc:: ExitApp
Also, SendMode "Event" did not solve the problem.