Hotkeys in the Russian keyboard layout do not work

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Hotkeys in the Russian keyboard layout do not work

Post by AZJIO »

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.

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
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: Hotkeys in the Russian keyboard layout do not work

Post by AAT »

Hi, AZJIO
Windows XP: I have no problems with hotkeys in either English or Russian keyboard layout.
Olli
Addict
Addict
Posts: 1242
Joined: Wed May 27, 2020 12:26 pm

Re: Hotkeys in the Russian keyboard layout do not work

Post by Olli »

AZJIO wrote:I have Win10 x64 1809, in the Russian keyboard layout does not work.
Same version.

Please see here.

There is a little code in the last message : it is just a DirectX initializing and executing. You can remove the text draws and add a quit after a decade of loops, and, normally, it removes the problem.

And you are not forced to flip the buffers, if you do not like a whole black screen effect.
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: Hotkeys in the Russian keyboard layout do not work

Post by AZJIO »

I was answered by 8 people on another forum (Win 11 21Н2, 8.1x64, Win10x64 Pro 21H2, Win7, Win10 x64 1709), it works for everyone. So you can ignore it, the problem is in my OS.
My computer is not a laptop.

I checked Ctrl+J and it works for both languages. There is probably a problem with Alt, which should not be used as a single modifier, because it forces you to activate keyboard shortcuts.
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: Hotkeys in the Russian keyboard layout do not work

Post by AZJIO »

Since I couldn't assign other characters other than letters as hotkeys, I made the gadget using WinAPI, using the examples on AutoIt3.

Code: Select all

EnableExplicit

Enumeration Gadget
	#GadgetHK
	#btnApply
EndEnumeration

Enumeration Hotkey
	#HK_ID = 1001
; 	#HK_ID2
EndEnumeration

#Window = 0

Define HotkeyCode.l
Define VirtKey
Define ModKey
Define hGUI, hHotkey, hFont
Define flgHK

; Not a required function, only to save to an ini file
Procedure.s GetKey(HotkeyCode)
	Protected ModKey, Key$, sep$ = " + "
	ModKey = HotkeyCode >> 8
	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 & $FF)
	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
	hHotkey = CreateWindowEx_(0, #HOTKEY_CLASS, 0, #WS_CHILD | #WS_VISIBLE | #WS_TABSTOP,10, 10, 200, 25, hGUI, 0, 0, 0)
	SendMessage_(hHotkey, #HKM_SETHOTKEY, #PB_Shortcut_J | (#HOTKEYF_CONTROL << 8), 0)
	hFont = LoadFont(0, "Arial", 11)
	If hFont
		SendMessage_(hHotkey, #WM_SETFONT, hFont, #True)
	EndIf
	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 = SendMessage_(hHotkey, #HKM_GETHOTKEY, 0, 0)
						If Not HotkeyCode
							Debug "Cancel the hotkey (Backspace)"
							flgHK = 0
							Continue
						EndIf
						Debug HotkeyCode
						Debug GetKey(HotkeyCode)
						ModKey = GetModKey(HotkeyCode >> 8) ; HiWord
						VirtKey = HotkeyCode & $FF ; LoWord
						If RegisterHotKey_(hGUI, #HK_ID, ModKey, VirtKey)
							flgHK = 1
						Else
							Debug "Failed to register hotkey"
							flgHK = 0
						EndIf
				EndSelect
			Case #PB_Event_CloseWindow
				DestroyWindow_(hHotkey)
				If flgHK
					UnregisterHotKey_(hGUI, #HK_ID)
				EndIf
				CloseWindow(#Window)
				End
		EndSelect
	ForEver
EndIf
Olli
Addict
Addict
Posts: 1242
Joined: Wed May 27, 2020 12:26 pm

Re: Hotkeys in the Russian keyboard layout do not work

Post by Olli »

I do not reach to understand your problem exactly : if you have an exact example of 'hotkey' that you can tell, I could understand.

What I have same is the version of the OS (1809).

I have a french keyboard. And I rewrite here because an other key (right arrow) was wrong recently. I reexecute my simple code (openscreen etc...) and added a drawtext("->") if keyboardpushed(#pb_key_right), and, very strangely, the problem has again disappeared...
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: Hotkeys in the Russian keyboard layout do not work

Post by AZJIO »

Olli wrote: Fri Feb 25, 2022 8:15 pm if you have an exact example of 'hotkey' that you can tell,
Alt + J

----------------
Perhaps I made the second code in vain. My keys were just occupied, so they were not assigned.
Olli
Addict
Addict
Posts: 1242
Joined: Wed May 27, 2020 12:26 pm

Re: Hotkeys in the Russian keyboard layout do not work

Post by Olli »

So execute it, test it, and test, after this, the 'hotkey' on Windows. Note that, on the french keyboard, the left alt key is reserved for switch on, or off, the windows menu. So I cannot get a backslash which requires to press on AltGr+8 : Just the right alt key (AltGr) can do it.

Code: Select all

InitSprite()
InitKeyboard()
ExamineDesktops()
dw = DesktopWidth(0)
dh = DesktopHeight(0)
OpenScreen(dw, dh, 32, "")
Repeat
 ExamineKeyboard()
 Delay(1)
 ClearScreen(0)
 If StartDrawing(ScreenOutput() )
  If KeyboardPushed(#PB_Key_LeftAlt)
   DrawText(0, 0, "Alt", #White)
  EndIf
  If KeyboardPushed(#PB_Key_RightAlt)
   DrawText(0, 16, "AltGr", #White)
  EndIf
  If KeyboardPushed(#PB_Key_J)
    DrawText(0, 32, "J", #White)
  EndIf
  StopDrawing()
 EndIf
 FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: Hotkeys in the Russian keyboard layout do not work

Post by AZJIO »

I have everything displayed, the right and left keys work each for themselves
Olli
Addict
Addict
Posts: 1242
Joined: Wed May 27, 2020 12:26 pm

Re: Hotkeys in the Russian keyboard layout do not work

Post by Olli »

Ok : during the code executing, you have everything ok.

But after ? After the code executing, does the behaviour of the desktop keyboard change ?
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: Hotkeys in the Russian keyboard layout do not work

Post by AZJIO »

What should change?

Maybe you should try "hook" https://www.purebasic.fr/english/viewto ... 54#p580454
Search the forum for other examples based on "hook".
Olli
Addict
Addict
Posts: 1242
Joined: Wed May 27, 2020 12:26 pm

Re: Hotkeys in the Russian keyboard layout do not work

Post by Olli »

No need 'hook'. My problem was solved just by executing my short code above, which changes back (resets) the behaviour of the desktop, certainly by flushing.

My last question is to check if my short code solves your problem too.
Post Reply