pressed Ctrl+

Just starting out? Need help? Post your questions and find answers here.
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: pressed Ctrl+

Post 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
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Quin
Addict
Addict
Posts: 1122
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: pressed Ctrl+

Post 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.
User avatar
HeX0R
Addict
Addict
Posts: 1187
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: pressed Ctrl+

Post 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
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: pressed Ctrl+

Post 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
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
HeX0R
Addict
Addict
Posts: 1187
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: pressed Ctrl+

Post 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.
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: pressed Ctrl+

Post 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
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: pressed Ctrl+

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4945
Joined: Sun Apr 12, 2009 6:27 am

Re: pressed Ctrl+

Post 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
Egypt my love
BarryG
Addict
Addict
Posts: 4121
Joined: Thu Apr 18, 2019 8:17 am

Re: pressed Ctrl+

Post by BarryG »

[Deleted]
Last edited by BarryG on Wed Mar 19, 2025 8:27 am, edited 1 time in total.
Quin
Addict
Addict
Posts: 1122
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: pressed Ctrl+

Post 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.
User avatar
HeX0R
Addict
Addict
Posts: 1187
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: pressed Ctrl+

Post by HeX0R »

BarryG wrote: Tue Mar 18, 2025 9:58 pm This is what OP wants.[...]
Initially, yes, later, not.
BarryG
Addict
Addict
Posts: 4121
Joined: Thu Apr 18, 2019 8:17 am

Re: pressed Ctrl+

Post by BarryG »

Oh, sorry, I must've missed something. :oops: I only read the first few posts.
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 151
Joined: Thu Dec 28, 2023 9:04 pm

Re: pressed Ctrl+

Post 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!
Post Reply