Page 2 of 2
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 6:38 pm
by normeus
Do you have an actual keypad on your keyboard? if you do, the example from the help file will work ( modified for CTRL + and - ). Anyway, take a look at the event loop.
You should be looking for a "menu" event not just any event then select the menu event:
Code: Select all
#Window = 0
Enumeration Menu
#Menu
#PopupMenu
EndEnumeration
Enumeration Menu_items
#mOpen
#mCopy
#mDummy
EndEnumeration
If OpenWindow(#Window, 200, 200, 200, 100, "Press Ctrl+D")
If CreateMenu(#Menu, WindowID(#Window)) ; Create a regular menu with title and one item
MenuTitle("File")
MenuItem(#mOpen, "Open" + #TAB$ + "Ctrl+ - on key pad only")
EndIf
If CreatePopupMenu(#PopupMenu) ; Create an additional pop-up menu
MenuItem(#mCopy, "Copy" + #TAB$ + "Ctrl+Shift+C")
EndIf
AddKeyboardShortcut(#Window, #PB_Shortcut_Control| #PB_Shortcut_Add, #mDummy) ; keyboard shortcut standalone (without menu item)
AddKeyboardShortcut(#Window, #PB_Shortcut_Control| #PB_Shortcut_Subtract, #mOpen) ; shortcut for the menu item
AddKeyboardShortcut(#Window, #PB_Shortcut_Control | #PB_Shortcut_Shift | #PB_Shortcut_C, #mCopy) ; shortcut for the pop-up menu item
Repeat
Select WaitWindowEvent()
Case #PB_Event_RightClick ; Display the pop-up menu on right mouse-click
DisplayPopupMenu(#PopupMenu, WindowID(#Window))
Case #PB_Event_Menu
Select EventMenu()
Case #mDummy : Debug "Control Plus"
Case #mOpen : Debug "Control Minus"
Case #mCopy : Debug "Copy"
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
norm
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 7:04 pm
by Quin
Seemingly not, and you can't even do it by checking #PB_Shortcut_Shift | #PB_Shortcut_Equals, because there's no #PB_Shortcut_Equals constant! These should definitely be added IMO.
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 7:37 pm
by HeX0R
Just played with it, does that trigger the plus and minus keys, no matter the keyboard layout?
Code: Select all
OpenWindow(0, 200, 200, 200, 100, "Bla")
AddKeyboardShortcut(0, 187, 0) ;#VK_OEM_PLUS
AddKeyboardShortcut(0, 188, 1) ;#VK_OEM_COMMA
AddKeyboardShortcut(0, 189, 2) ;#VK_OEM_MINUS
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
Select EventMenu()
Case 0 : Debug "Plus"
Case 1 : Debug "Comma"
Case 2 : Debug "Minus"
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
Answering my own question now, according to MSDN, yes (on Windows at least) =>
https://learn.microsoft.com/en-us/windo ... -key-codes
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 8:04 pm
by normeus
Code: Select all
#window=0
#ctrlplus=1 ;need to press shift on your keybard otherwise you'll get = not +
#ctrlminus=2 ; need to press shift to get minus
OpenWindow(#window, 0, 0, 250, 105, "you need to also press shift to get to your character..", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
AddKeyboardShortcut(#window, #PB_Shortcut_Shift|#PB_Shortcut_Control|#VK_OEM_PLUS, #ctrlplus)
AddKeyboardShortcut(#window, #PB_Shortcut_Shift|#PB_Shortcut_Control|#VK_OEM_MINUS, #ctrlminus)
Repeat
whatevent = WaitWindowEvent()
Select whatevent
Case #PB_Event_Menu
whatkey= EventMenu()
Select whatkey
Case #ctrlplus
Debug("pressed shift ctrl + , if you do not press shift then you do not get a + you get equal")
Case #ctrlminus
Debug("pressed shift ctrl + , if you do not press shift then you do not get a + you get equal")
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
End
Your sample code
Norm
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 8:14 pm
by HeX0R
I think the different keyboard layouts are the problem here, e.g. on a German Keyboard, there is no equal key, equal is SHIFT + 0.
That might be difficult to handle, not sure if Linux and... that other thing, have also such kind of layout-independent OEM constants.
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 8:34 pm
by ChrisR
HeX0R wrote: Tue Mar 18, 2025 7:37 pm
Just played with it, does that trigger the plus and minus keys, no matter the keyboard layout?
No, not here, on my Acer laptop with a French Azerty keyboard and numeric keypad.
Here it works with: #PB_Shortcut_Add, #PB_Shortcut_Decimal, #PB_Shortcut_Subtract
I guess it should be done using both Virtual-Key
Code: Select all
OpenWindow(0, 200, 200, 200, 100, "Bla")
AddKeyboardShortcut(0, #PB_Shortcut_Add, 0) : AddKeyboardShortcut(0, #VK_OEM_PLUS, 0) ;
AddKeyboardShortcut(0, #PB_Shortcut_Decimal, 1) : AddKeyboardShortcut(0, #VK_OEM_COMMA, 1)
AddKeyboardShortcut(0, #PB_Shortcut_Subtract, 2) : AddKeyboardShortcut(0, #VK_OEM_MINUS, 2) ;
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
Select EventMenu()
Case 0 : Debug "Plus"
Case 1 : Debug "Comma"
Case 2 : Debug "Minus"
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 8:39 pm
by AZJIO
HeX0R wrote: Tue Mar 18, 2025 8:14 pm
if Linux and.
If I register keyboard shortcuts in Linux, in Cinnamon, then I do it for the Russian and English layouts. It's like they're attached to a letter, not a key.
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 9:20 pm
by RASHAD
Ctrl + for Numpad & Keyboard
Code: Select all
OpenWindow(0, 200, 200, 200, 100, "Bla")
AddKeyboardShortcut(0,#PB_Shortcut_Control|107 ,10)
AddKeyboardShortcut(0,#PB_Shortcut_Control|187, 20)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
Select EventMenu()
Case 10 : Debug "Plus Numpad"
Case 20 : Debug "Plus Keyboard"
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 9:58 pm
by BarryG
[Deleted]
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 10:07 pm
by Quin
BarryG wrote: Tue Mar 18, 2025 9:58 pm
This is what OP wants. Only works when the window has the focus.
Code: Select all
#window=0
#ctrlplus=1
#ctrlminus=2
OpenWindow(#window, 0, 0, 250, 105, "pressed key..", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
AddKeyboardShortcut(#window, #PB_Shortcut_Control| #PB_Shortcut_Add, #ctrlplus)
AddKeyboardShortcut(#window, #PB_Shortcut_Control| #PB_Shortcut_Subtract, #ctrlminus)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Menu
Select EventMenu()
Case #ctrlplus : Debug("pressed ctrl+")
Case #ctrlminus : Debug("pressed ctrl-")
EndSelect
EndIf
Until EventID = #PB_Event_CloseWindow
No it isn't, that only applies to the numpad I'm afraid.
Re: pressed Ctrl+
Posted: Tue Mar 18, 2025 10:08 pm
by HeX0R
BarryG wrote: Tue Mar 18, 2025 9:58 pm
This is what OP wants.[...]
Initially, yes,
later, not.
Re: pressed Ctrl+
Posted: Wed Mar 19, 2025 8:23 am
by BarryG
Oh, sorry, I must've missed something.

I only read the first few posts.
Re: pressed Ctrl+
Posted: Wed Mar 19, 2025 11:49 am
by rndrei
All examples above do not work. I work on Linux. Keyboard without pad. The solution has not been found. I wrote a post in future versions of PureBasic. I hope they solve this problem!