Page 1 of 1

Simulate button gadget is pressed

Posted: Sat Feb 01, 2025 5:35 am
by Allen
Hi all,

I am looking for a method to simulate a button gadget is pressed. I searched the forum and found this command :
"PB_Gadget_SendGadgetCommand(GadgetID(#Gadget), #PB_EventType_LeftClick)"

However, it seems this command is no longer available, any suggestion?

Thanks

Allen

Re: Simulate button gadget is pressed

Posted: Sat Feb 01, 2025 5:54 am
by idle
something like this

Code: Select all

Procedure SetClick() 
   
  PostEvent(#PB_Event_Gadget ,0,1,#PB_EventType_LeftClick) 
  
EndProcedure   

Procedure GotClick() 
  Debug "gotclick" 
EndProcedure   


If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, 10, 10, 200, 20, "Send click to button")
    ButtonGadget(1, 10, 40, 200, 20, "Button", #PB_Button_Left)
   
    BindGadgetEvent(0,@SetClick(),#PB_EventType_LeftClick) 
    BindGadgetEvent(1,@gotClick(),#PB_EventType_LeftClick) 
    Repeat 
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf

Re: Simulate button gadget is pressed

Posted: Sat Feb 01, 2025 6:19 am
by Allen
Hi Idle,

Thanks you for the example, it is what I am looking for.

Thanks

Allen

Re: Simulate button gadget is pressed

Posted: Sat Feb 01, 2025 7:48 am
by morosh
PB_Gadget_SendGadgetCommand still working here:

Code: Select all

Import  ""
  PB_Gadget_SendGadgetCommand(hWnd, EventType)
EndImport


Procedure SetClick() 
  PB_Gadget_SendGadgetCommand(GadgetID(1), #PB_EventType_LeftClick)
EndProcedure   

Procedure GotClick() 
  Debug "gotclick" 
EndProcedure   


If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, 10, 10, 200, 20, "Send click to button")
    ButtonGadget(1, 10, 40, 200, 20, "Button", #PB_Button_Left)
   
    BindGadgetEvent(0,@SetClick(),#PB_EventType_LeftClick) 
    BindGadgetEvent(1,@gotClick(),#PB_EventType_LeftClick) 
    Repeat 
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
using PB6.20b1

Re: Simulate button gadget is pressed

Posted: Sat Feb 01, 2025 11:59 am
by mk-soft
Not used. Is implemented as a PostEvent

Re: Simulate button gadget is pressed

Posted: Sat Feb 01, 2025 12:45 pm
by Fred
PostEvent() is better than relying on undocumented internals