Hotkeys in the Russian keyboard layout do not work
Posted: Fri Feb 11, 2022 8:57 am
2 people did the test, they have no problem, only me have a problem.
I have Win10 x64 1809, in the Russian keyboard layout does not work.
In AutoIt3, if the registration of hotkeys took place with the English keyboard layout, then they remain working in the Russian keyboard layout, so in AutoIt3 I check the current keyboard layout and if it is Russian, then I remember the flag, switch to En, register the keys, return Ru.
I have Win10 x64 1809, in the Russian keyboard layout does not work.
In AutoIt3, if the registration of hotkeys took place with the English keyboard layout, then they remain working in the Russian keyboard layout, so in AutoIt3 I check the current keyboard layout and if it is Russian, then I remember the flag, switch to En, register the keys, return Ru.
Code: Select all
EnableExplicit
Enumeration Gadget
#GadgetHK
#btnApply
EndEnumeration
Enumeration Hotkey
#HK_ID = 1001
; #HK_ID2
EndEnumeration
#Window = 0
Define HotkeyCode
Define VirtKey
Define ModKey
Define hGUI
Define flgHK
; Not a required function, only to save to an ini file
Procedure.s GetKey(HotkeyCode)
Protected ModKey, Key$, sep$ = " + "
ModKey = HotkeyCode >> 16
If ModKey & #HOTKEYF_CONTROL
Key$ + sep$ + "Ctrl"
EndIf
If ModKey & #HOTKEYF_SHIFT
Key$ + sep$ + "Shift"
EndIf
If ModKey & #HOTKEYF_ALT
Key$ + sep$ + "Alt"
EndIf
Key$ + sep$ + Chr(HotkeyCode & $FFFF)
Key$ = Mid(Key$, Len(sep$) + 1)
ProcedureReturn Key$
EndProcedure
Procedure GetModKey(MOD)
Protected ModKey = 0
If MOD & #HOTKEYF_SHIFT
ModKey | #MOD_SHIFT
EndIf
If MOD & #HOTKEYF_CONTROL
ModKey | #MOD_CONTROL
EndIf
If MOD & #HOTKEYF_ALT
ModKey | #MOD_ALT
EndIf
ProcedureReturn ModKey
EndProcedure
;- GUI
hGUI = OpenWindow(#Window, 0, 0, 240, 70, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If hGUI
ShortcutGadget(#GadgetHK, 10, 10, 200, 25, #PB_Shortcut_Alt | #PB_Shortcut_J)
; SetGadgetState(0 , #PB_Shortcut_Control | #PB_Shortcut_B) ; can be inserted this way
ButtonGadget(#btnApply, 10, 40, 100, 28, "Apply")
Repeat
Select WaitWindowEvent()
Case #WM_HOTKEY
Select EventwParam()
Case #HK_ID
Debug "hotkey called"
; MessageRequester("", "1") ; for a test of a compiled program
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #btnApply
If flgHK And Not UnregisterHotKey_(hGUI, #HK_ID) ; reassignment works without unregistering
Debug "Could not unregister the hotkey"
Continue
EndIf
HotkeyCode = GetGadgetState(#GadgetHK)
If Not HotkeyCode
Debug "Cancel the hotkey (Backspace)"
flgHK = 0
Continue
EndIf
Debug HotkeyCode
Debug GetKey(HotkeyCode)
ModKey = GetModKey(HotkeyCode >> 16) ; HiWord
VirtKey = HotkeyCode & $FFFF ; LoWord
If RegisterHotKey_(hGUI, #HK_ID, ModKey, VirtKey)
flgHK = 1
Else
Debug "Failed to register hotkey"
flgHK = 0
EndIf
EndSelect
Case #PB_Event_CloseWindow
If flgHK
UnregisterHotKey_(hGUI, #HK_ID)
EndIf
CloseWindow(#Window)
End
EndSelect
ForEver
EndIf