Capturing Enter in PB, to imitate behaviour of other applications, can be a challenge in my own experience, especially with EditorGadget.Gérard wrote: Sat Dec 07, 2024 11:36 amCode: Select all
VK_RETURN = GetAsyncKeyState_(#VK_RETURN) If VK_RETURN > 1 Select ActiveGadget Case 0, 1 Debug "Button "+ActiveGadget+" pressed by Enter" EndSelect EndIf EndIf
As soon as the below programme executes, an unrelated button event is triggered. Clicking inside the EditorGadget, triggers a double-button response. Then even entering a single character keypress in the EditorGadget also triggers a double-button response.
Code: Select all
Enumeration Window
#WinApp
EndEnumeration
If OpenWindow(#WinApp, 0, 0, 622, 530, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
ButtonImageGadget(1, 10, 40, 200, 20, 9)
TextGadget(20, 10, 135, 140, 25, "Editor Gadget")
EditorGadget(21, 10, 160, 445, 200, #PB_Editor_WordWrap)
SetActiveGadget(0)
Repeat
ev = WaitWindowEvent()
If GetActiveWindow() = #WinApp
ActiveGadget = GetActiveGadget()
VK_RETURN = GetAsyncKeyState_(#VK_RETURN)
If VK_RETURN > 1
Select ActiveGadget
Case 0, 1
Debug "Button "+ActiveGadget+" pressed by Enter"
EndSelect
EndIf
EndIf
If ev = #PB_Event_Gadget
Debug "Button pressed" ; <- This is the goal when I press Enter on a ButtonGadget/ButtonImageGadget.
EndIf
Until ev = #PB_Event_CloseWindow
EndIf