pressed "ENTER" key

Linux specific forum
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 153
Joined: Thu Dec 28, 2023 9:04 pm

pressed "ENTER" key

Post by rndrei »

Hello! How can I tell if the "ENTER" key was pressed?
Linux system

Code: Select all

EditorGadget(#EDITOR,1,2, Window_Width, Window_Height)
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: pressed "ENTER" key

Post by PBJim »

The way I do this generally, is to set a keyboard shortcut. The Enter key is then intercepted for the window — not specific to the gadget — and treated as a menu event. I haven't tried this with Linux, as I only work with Windows, but AddKeyboardShortcut indicates it is for all O/S.

There may be easier ways, but it's the way I do it.

Code: Select all

Enumeration Key_Shortcuts
  #EnterKey
EndEnumeration

Window_0 = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 410, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Text_0 = TextGadget(#PB_Any, 30, 25, 240, 30, "Test - Press Enter")
Editor_0 = EditorGadget(#PB_Any, 30, 55, 350, 200)

AddKeyboardShortcut(Window_0, #PB_Shortcut_Return, #EnterKey)           ; Keyboard shortcut standalone (without menu item)

Repeat
  event = WaitWindowEvent()
  
  Select event
    Case #PB_Event_CloseWindow
      Break
      
    Case #PB_Event_Menu                                                 ; Dummy menu to allow ENTER key as 'default'
      Select EventMenu()
          
        Case #EnterKey
          SetGadgetText(Text_0, "Enter key pressed")
          
      EndSelect

    Case #PB_Event_Gadget

  EndSelect
  
ForEver
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 153
Joined: Thu Dec 28, 2023 9:04 pm

Re: pressed "ENTER" key

Post by rndrei »

It works, thanks!
Post Reply