PB_Key_Colon

Just starting out? Need help? Post your questions and find answers here.
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 185
Joined: Thu Dec 28, 2023 9:04 pm

PB_Key_Colon

Post by rndrei »

How do I know if the colon key is pressed?
it's not work!

Code: Select all

OpenWindow(0,0,0,200,200,"colon pushed")
Repeat
    Event = WaitWindowEvent()
    Select Event
        Case #PB_Key_Colon
             Debug "pressed [:]"
        Case #PB_Event_CloseWindow
            End
    EndSelect
ForEver
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB_Key_Colon

Post by mk-soft »

#PB_Key_Colon: This constant does not exist.

For "WaitWindowEvent()" There are certain events and no more. See WindowEvent()

The operating system passes the user input to the Controls (Gadgets). A window has no keyboard, as well as a button has no keyboard.
A StringGadget or EditorGadget does. Thus, this can only be programmed LowLevel.

https://learn.microsoft.com/en-us/windo ... -key-codes

Only Windows

Code: Select all

;-TOP

Procedure WinCB(hWnd, uMSg, wParam, lParam)
  Select uMSg
    Case #WM_KEYDOWN
      Debug "Virtuel Key Code 0x" + Hex(wParam)
      
  EndSelect
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("&File")
    MenuItem(99, "E&xit")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    SetWindowCallback(@WinCB())
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            Case 99
              PostEvent(#PB_Event_CloseWindow, 0, 0)
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: PB_Key_Colon

Post by Demivec »

Here's another way using keyboard shortcuts that generate menu events:

Code: Select all

#w_main = 0           ;window
#event_selectedShortcut = 100 ;event
#My_Shortcut_Colon = 186 + #PB_Shortcut_Shift ;constant obtained from Shortcut gadget test

OpenWindow(#w_main,0,0,200,200,"colon pushed")
AddKeyboardShortcut(#w_main, #My_Shortcut_Colon, #event_selectedShortcut)
Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_Menu
      If EventMenu() = #event_selectedShortcut
        Debug "pressed [:]" 
      EndIf
      
    Case #PB_Event_CloseWindow
      End
  EndSelect
ForEver
The only unusual part of this is that the shortcut value is not listed in the help manual with other constants but it was obtained by using the ShortcutGadget() to generate the value by pushing the desired key combination (Shift+;).

The following code shows how this was done:

Code: Select all

#g_ShortcutSelect = 0 ;gadget
#w_main = 0           ;window
;#My_Shortcut_SemiColon = 186 ;constant obtained from Shortcut gadget test

OpenWindow(#w_main,0,0,200,200,"colon pushed")
ShortcutGadget(#g_ShortcutSelect,10,10,180,40,0)
Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_Gadget
      currentShortcut = GetGadgetState(0)
      Debug "value of shortcut selected:" + currentShortcut
    Case #PB_Event_CloseWindow
      End
  EndSelect
ForEver
I made these tests using a Windows 11 OS.
User avatar
TI-994A
Addict
Addict
Posts: 2752
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: PB_Key_Colon

Post by TI-994A »

rndrei wrote: Thu Oct 23, 2025 10:28 pmHow do I know if the colon key is pressed?
The canvas gadget includes a feature to receive keyboard focus and keyboard events, and can be easily implemented for unobtrusively trapping keystrokes.

Code: Select all

OpenWindow(0, 0, 0, 200, 200, "colon pushed", #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 200, 200, #PB_Canvas_Keyboard)
SetActiveGadget(0)
Repeat
  event = WaitWindowEvent()
  Select event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          If EventType() = #PB_EventType_KeyDown
            key = GetGadgetAttribute(0, #PB_Canvas_Input)
            If Chr(key) = ":"
              Debug "pressed [:]"            
            EndIf          
          EndIf
      EndSelect
    Case #PB_Event_CloseWindow
      End
  EndSelect
ForEver

Another convenient and cross-platform solution. :)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: PB_Key_Colon

Post by jacdelad »

rndrei wrote: Thu Oct 23, 2025 10:28 pm How do I know if the colon key is pressed?
it's not work!

Code: Select all

OpenWindow(0,0,0,200,200,"colon pushed")
Repeat
    Event = WaitWindowEvent()
    Select Event
        Case #PB_Key_Colon
             Debug "pressed [:]"
        Case #PB_Event_CloseWindow
            End
    EndSelect
ForEver
One Sidenote: when Selecting an event, as the return value of WaitWindowEvent, the value is a #PB_Event_...,-constant.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB_Key_Colon

Post by mk-soft »

Code: Select all

#My_Shortcut_Colon_EN = 186 + #PB_Shortcut_Shift ;constant obtained from Shortcut gadget test
#My_Shortcut_Colon_DE = 190 + #PB_Shortcut_Shift ;constant obtained from Shortcut gadget test
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 487
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: PB_Key_Colon

Post by Mindphazer »

Code: Select all

#My_Shortcut_Colon_FR = 191 ;constant obtained from Shortcut gadget test
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 185
Joined: Thu Dec 28, 2023 9:04 pm

Re: PB_Key_Colon

Post by rndrei »

Figured it out, thank you!
Post Reply