Button held down

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Victory
Experienced Solver
Experienced Solver
Posts: 98
Joined: Fri Mar 19, 2010 1:20 am

Button held down

Post by Victory » Mon Dec 03, 2012 6:03 pm

What is the easiest way to know whether a wxButton is currently pressed down (i.e., mouse held down on the button)? I imagine I should be able to implement that by tracking the mouse down and mouse up events on the button myself. But, I am wondering whether there is an easier way than that?

My use case : I have a "Zoom in" button in my application. When that is held down, I want to continue zooming in instead of the user having to keep clicking the button for each incremental zoom in.

Thanks.

User avatar
doublemax
Moderator
Moderator
Posts: 15170
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Button held down

Post by doublemax » Mon Dec 03, 2012 6:31 pm

There is no direct and easy way. Usually you'd start a timer when the button is pressed down. In the timer event handler you perform the zooming/whatever. When the button is released, stop the timer again.
Use the source, Luke!

Victory
Experienced Solver
Experienced Solver
Posts: 98
Joined: Fri Mar 19, 2010 1:20 am

Re: Button held down

Post by Victory » Tue Dec 04, 2012 12:11 am

But, wxButton does not have separate events corresponding to "press down" and "Release" situations; right? I see only a "click" event listed in the document.

Basically, I need an event to start zooming in and another event to stop.

Thanks!

User avatar
doublemax
Moderator
Moderator
Posts: 15170
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Button held down

Post by doublemax » Tue Dec 04, 2012 12:21 am

Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 449
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: Button held down

Post by mael15 » Fri Aug 21, 2020 1:01 pm

I there still no easy way to repeat a function call as long as the user holds down the mouse button? Still have to use a wxTimer?

User avatar
doublemax
Moderator
Moderator
Posts: 15170
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Button held down

Post by doublemax » Fri Aug 21, 2020 4:22 pm

mael15 wrote:
Fri Aug 21, 2020 1:01 pm
I there still no easy way to repeat a function call as long as the user holds down the mouse button?
No.
Use the source, Luke!

Post Reply