Page 1 of 1
Canvas ALT modifier is not recognised - Bug?
Posted: Fri May 30, 2025 5:18 pm
by Joubarbe
Code: Select all
OpenWindow(0, 0, 0, 50, 50, "")
CanvasGadget(0, 0, 0, 50, 50, #PB_Canvas_Keyboard)
SetActiveGadget(0)
Procedure OnKeyUp()
Debug GetGadgetAttribute(0, #PB_Canvas_Key)
Debug GetGadgetAttribute(0, #PB_Canvas_Modifiers)
EndProcedure
BindGadgetEvent(0, @OnKeyUp(), #PB_EventType_KeyUp)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Shift and Control (and AltGr) work OK, but not Alt. Am I missing something?
Documentation:
#PB_Canvas_Alt : The 'alt' key is currently pressed.
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Fri May 30, 2025 5:30 pm
by Fred
It works here, it display '2' when alt + another key is pressed (Win10)
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Fri May 30, 2025 8:50 pm
by Joubarbe
Hmm, interesting. I'm on Win11. There's a typical Windows error sound when I combine Alt and another key. (always shows 0)
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Fri May 30, 2025 8:54 pm
by wombats
I'm on Windows 11. I hear the Windows error sound and see 2 when Alt and another key are pressed and 0 when just Alt is pressed.
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Fri May 30, 2025 9:52 pm
by User_Russian
Left Alt doesn't work. Right Alt works, but GetGadgetAttribute(0, #PB_Canvas_Modifiers) returns 6, not 2.
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Sat May 31, 2025 5:30 am
by Joubarbe
Well, I would consider this a bug. Please move this thread to the bug section if you find it appropriate.
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Sat May 31, 2025 7:10 am
by jacdelad
User_Russian wrote: Fri May 30, 2025 9:52 pm
Left Alt doesn't work. Right Alt works, but GetGadgetAttribute(0, #PB_Canvas_Modifiers) returns 6, not 2.
Aren't left and right Alt two different keys? Alt and AltGr??
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Sat May 31, 2025 7:52 am
by Joubarbe
jacdelad wrote: Sat May 31, 2025 7:10 am
User_Russian wrote: Fri May 30, 2025 9:52 pm
Left Alt doesn't work. Right Alt works, but GetGadgetAttribute(0, #PB_Canvas_Modifiers) returns 6, not 2.
Aren't left and right Alt two different keys? Alt and AltGr??
They are indeed. I'm talking about Left Alt, the right one also works fine with me. Same as User_Russian.
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Sat May 31, 2025 7:57 am
by HeX0R
Alt Gr ("right" Alt) = Alt (2) + CTRL (4), therefore = 6
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Sat May 31, 2025 8:51 am
by Fred
You mean when it's pressed without any other keys ?
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Sat May 31, 2025 9:25 am
by User_Russian
jacdelad wrote: Sat May 31, 2025 7:10 am
User_Russian wrote: Fri May 30, 2025 9:52 pm
Left Alt doesn't work. Right Alt works, but GetGadgetAttribute(0, #PB_Canvas_Modifiers) returns 6, not 2.
Aren't left and right Alt two different keys? Alt and AltGr??
In PB there is only one Alt , not right and left, so they must be the same.
https://www.purebasic.com/documentation ... adget.html Code: Select all
#PB_Canvas_Modifiers
Returns the state of the keyboard modifiers for the event. The result is a combination (using bitwise or) of the following values:
#PB_Canvas_Shift : The 'shift' key is currently pressed.
#PB_Canvas_Alt : The 'alt' key is currently pressed.
#PB_Canvas_Control: The 'control' key is currently pressed.
#PB_Canvas_Command: The 'command' (or "apple") key is currently pressed. (Mac OSX only)
Fred wrote: Sat May 31, 2025 8:51 am
You mean when it's pressed without any other keys ?
No, with any other keys. For example, left Alt and space. With PB 6.20 and previous, it doesn't work.
With PB 6.21 beta, it works.
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Sat May 31, 2025 2:58 pm
by Olli
(W10
PB 600 LTS x64 demo)
real left alt key : nothing (OS behaviour okay -> alt+F4 alt+space etc...)
real right alt key : modifier code = 6
note :
left and right Control key modifier code = 4
left and right Shift key modifier code = 1
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Sat May 31, 2025 3:39 pm
by Olli
I think the left Alt key is reserved for the OS.
With this key, we can :
- switch the menu on or off. (Alt + nothing)
- access to the window properties (Alt+Space)
- quit the window (Alt+F4)
- change the active task (Alt+Tab)
etc...
A way to use more 'normally' the left Alt key is in creating a menu item shortcut, targetting a specific key (ex : Q)
Code: Select all
; (once the window is created)
; (callback procedure is already created and named onKey() )
; (objects identifiers are zeroed)
; (assigning randomly a menu item identifier. Ex : $F001)
CreateMenu(0, WindowID(0) )
AddKeyboardShortcut(0, #PB_Shortcut_Alt | #PB_Shortcut_Q, $F001)
BindMenuEvent(0, $F001, @onKey() )
In this way, the key code and modifier code are 0 (zero). So, a condition can be made to get the menu item code (here EventMenu() = $F001) the shortcut has activated.
The Alt right key provides non zeroed key code and modifer code, allowing the coder to separate a left alt key from a right alt key.
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Sat May 31, 2025 3:59 pm
by Joubarbe
Fred wrote: Sat May 31, 2025 8:51 am
You mean when it's pressed without any other keys ?
Just to be clear, my goal here is to create a hotkey that has ALT as modifier. Example: ALT+E. If I do that,
GetGadgetAttribute(0, #PB_Canvas_Modifiers) will return 0. But if I do CTRL+E or SHIFT+E, a proper non-zero modifier code is returned, allowing me to properly detect the hotkey combination.
Besides, ALT is not detected by
GetGadgetAttribute(0, #PB_Canvas_Key) when hit independently. SHIFT and CTRL are.
@Olli: Yes I think it's "locked" by the OS indeed. But that would be great to overpass that with the standard functions.
Re: Canvas ALT modifier is not recognised - Bug?
Posted: Sat May 31, 2025 7:59 pm
by Olli
Joubarbe wrote: Sat May 31, 2025 3:59 pm
Just to be clear, my goal here is to create a hotkey that has ALT as modifier. Example: ALT+E. [...]
@Olli: Yes I think it's "locked" by the OS indeed. But that would be great to overpass that with the standard functions.
This
Alt key seems so reserved for the OS for the hotkeys. So, in PureBasic, a menu (invisible) shortcut should do the affair.
Normally, this below is okay :
Code: Select all
Enumeration 1234
#Alt_E
EndEnumeration
OpenWindow(0, 0, 0, 50, 50, "")
CanvasGadget(0, 0, 0, 50, 50, #PB_Canvas_Keyboard)
SetActiveGadget(0)
Procedure OnKeyUp()
Debug GetGadgetAttribute(0, #PB_Canvas_Key)
Debug GetGadgetAttribute(0, #PB_Canvas_Modifiers)
EndProcedure
Procedure hotKey()
Select EventMenu()
Case #Alt_E
Debug "Alt+E has been pressed"
EndSelect
EndProcedure
Define hotKeyMenu = CreateMenu(#PB_Any, WindowID(0) )
AddKeyboardShortcut(0, #PB_Shortcut_Alt | #PB_Shortcut_E, #Alt_E)
BindMenuEvent(hotKeyMenu, #Alt_E, @hotKey() )
BindGadgetEvent(0, @OnKeyUp(), #PB_EventType_KeyUp)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
For low level input, you must use the API functions :
GetKeyboardState() Microsoft documentation
Linux example