Jump to content

Need an elegant button press event (for press and hold)


hyperspherical

Recommended Posts

I'm looking for the correct way to add an event similar to GEVENT_GWIN_BUTTON for standard gwinButtonCreate() type buttons triggered from a touchscreen or possibly any input. 

The purpose is to create a type of latched state that is released by the normal GEVENT_GWIN_BUTTON.  This way I can immediately respond to a button press, set an output to a state and hold that state until the button which in this case is a touchscreen is released and thus debounced by the uGFX button state management.

I've attempted to create an event by using the customDraw (callout) parameter to capture the press state and to send my own  type of  GEVENT_GWIN_BUTTON back to the listeners so they can process the event and manage the latching output.

I started looking at the hacky way of calling _gwinSendEvent but that breaks the API and if I was going to do that I may as well hack my own event into the gwin_button code.  Although if I did add that code then I would also add the latch internally so that repeated events didn't occur. Basically adding GEVENT_GWIN_BUTTON_PRESS event.

Any ideas and code snippets ?

Link to comment
Share on other sites

5 hours ago, inmarket said:

If you want to create a latched button use the checkbox instead with a button draw routine instead of the normal checkbox draw routine. The draw routine already exists and the checkbox provides the latched button state and events you are after.

Hi inmarket,  I've tried your idea, but the issue with it is that I'd like to have a Button Release event. I need to know both when it's initially pressed and when it's finally release based on events rather than polling. The checkbox does give me an event when I press but doesn't seem to issue any events when it's released

The functional requirement is like this:

  1. Person presses a screen button and that triggers an output function.
  2. Whilst the button is still pressed the output continues.
  3. The person releases the button and the output stops.

If this is done with events then the button release event can trigger the appropriate output to stop. Otherwise I have to use a timer to poll that button, which is more tangled than just acting on the event.

I had one hacky idea, which was to swap the checkbox type to a button type after it was pressed ?  That way I'd could get a GEVENT_GWIN_CHECKBOX for the press and a GEVENT_GWIN_BUTTON for the release.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...