Page 1 of 1

PB_Key_Colon

Posted: Thu Oct 23, 2025 10:28 pm
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

Re: PB_Key_Colon

Posted: Thu Oct 23, 2025 11:37 pm
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()

Re: PB_Key_Colon

Posted: Fri Oct 24, 2025 2:34 am
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.

Re: PB_Key_Colon

Posted: Fri Oct 24, 2025 4:04 am
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. :)

Re: PB_Key_Colon

Posted: Fri Oct 24, 2025 6:33 am
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.

Re: PB_Key_Colon

Posted: Fri Oct 24, 2025 8:26 am
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

Re: PB_Key_Colon

Posted: Fri Oct 24, 2025 10:38 am
by Mindphazer

Code: Select all

#My_Shortcut_Colon_FR = 191 ;constant obtained from Shortcut gadget test

Re: PB_Key_Colon

Posted: Fri Oct 24, 2025 11:37 am
by rndrei
Figured it out, thank you!