How validate with the enter key?

Just starting out? Need help? Post your questions and find answers here.
bmld76
Posts: 27
Joined: Wed May 24, 2023 5:10 pm

How validate with the enter key?

Post by bmld76 »

Hello,

Do yo know how to validate a stringadget with the enter(rc) key ?

Cordially
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: How validate with the enter key?

Post by Peter »

use AddKeyboardShortcut() in combination with GetActiveGadget():

Code: Select all

Enumeration
  #Window
  #StringGadget
  #PB_Shortcut_Return_Event  
EndEnumeration


Procedure MenuEvents()
  
  If EventMenu() = #PB_Shortcut_Return_Event
    If GetActiveGadget() = #StringGadget
      Debug "Gotcha!"
    EndIf
  EndIf
  
  
EndProcedure

OpenWindow(#Window, 0, 0, 320, 260, "Shortcut", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

StringGadget(#StringGadget, 10, 10, 300, 30, "")

AddKeyboardShortcut(0, #PB_Shortcut_Return, #PB_Shortcut_Return_Event)

BindEvent(#PB_Event_Menu, @MenuEvents())

SetActiveGadget(#StringGadget)
bmld76
Posts: 27
Joined: Wed May 24, 2023 5:10 pm

Re: How validate with the enter key?

Post by bmld76 »

It's work, thank very much.
Post Reply