Simulate button click

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Simulate button click

Post by jak64 »

Good morning,

Is it possible to simulate a left mouse click on a buttongadget?

I searched the forum with "Simulate button click" but I did not find...

Thank you for your help
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Simulate button click

Post by Caronte3D »

Windows only:

Code: Select all

Macro MouseClick()
  mouse_event_(#MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
  mouse_event_(#MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
EndMacro

;

MouseClick()
PeDe
Enthusiast
Enthusiast
Posts: 119
Joined: Sun Nov 26, 2017 3:13 pm
Location: Vienna
Contact:

Re: Simulate button click

Post by PeDe »

For a button in your own code you can send an event:
PostEvent(#PB_Event_Gadget, WindowNumber, ButtonGadgetNumber, #PB_EventType_LeftClick)
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Simulate button click

Post by jak64 »

Hello Caronte3D,

What I want is to simulate a click as if I had clicked on a button (and not another) and for it to be detected in my While until loop by the Case corresponding to my button

I want to trigger this click on this button automatically in my program
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Simulate button click

Post by jak64 »

Hello PeDe,

If I understand correctly, I just have to put the following code idea:

PostEvent(#PB_Event_Gadget, #WindowsWindow, #MusicList, #PB_EventType_LeftClick)

where #WindowsWindow is my Windows window
and #MusicList the gadget that will receive the click
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Simulate button click

Post by Caronte3D »

Yes, but if the button is in the same (your) program, I think is better if you use a procedure for that button, so you simply call that procedure when you want the same functionallity of that button, no need to send events (if it's not a must for somethig).
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Simulate button click

Post by jak64 »

But yes, Caronte3D,

Am I stupid, should have thought about it...
Post Reply