Simulate button gadget is pressed

Just starting out? Need help? Post your questions and find answers here.
Allen
Enthusiast
Enthusiast
Posts: 103
Joined: Wed Nov 10, 2021 2:05 am

Simulate button gadget is pressed

Post 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
User avatar
idle
Always Here
Always Here
Posts: 5835
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Simulate button gadget is pressed

Post 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
Allen
Enthusiast
Enthusiast
Posts: 103
Joined: Wed Nov 10, 2021 2:05 am

Re: Simulate button gadget is pressed

Post by Allen »

Hi Idle,

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

Thanks

Allen
morosh
Enthusiast
Enthusiast
Posts: 329
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: Simulate button gadget is pressed

Post 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
PureBasic: Surprisingly simple, diabolically powerful
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Simulate button gadget is pressed

Post by mk-soft »

Not used. Is implemented as a PostEvent
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Simulate button gadget is pressed

Post by Fred »

PostEvent() is better than relying on undocumented internals
Post Reply