Murga-Projects Forums

Full Version: Space Bar presses FLTK buttons
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How to prevent this odd behavior?
There must be some setting I don't know about.

I have a button that opens a window, when I select a button on that window I thought closing the window would prevent its button from being hit twice, however the button on the first window gets hit and the window opens again.

Any ideas?
I'm not clear on what the situation is, but it sounds like a focus problem?

Space bar on a selected button will, as far as I know, always trigger the callback of that button.

You might need to override the default behavior by checking events, but like I said I'm not sure exactly what your issue is.
Well how can I make sure nothing is focused?

I did a little hack to make sure this particular button doesn't execute its default command every single time its pressed, but its hacky at best and I still have instances where the space bar grabs a button I don't want it to grab.

Basically this button in question is loading a game level, so I tested to see if the level was loaded and game mode was set, then it won't freak out. However I have another interface where a button sets the camera mode, after you turn the button/camera off, hitting the space bar gets the button again! This happens when in game mode and the game script is polling the space bar for something, like jumping.

Ideally there must be a way to deselect a whole interface or prevent the space bar from doing its wacky button press. I tried hiding the button in question, FLTK then pressed the next button available with space bar.

I suppose I could check the keyboard and then exit my functions if the space key has been pressed? Ah the simple solution becomes clear in the daylight.
Have you tried disabling the buttons while the game is active ?
This at the start of the button function worked:

if Fl:event_key() == 32 then return end

Dropped right out of the callback without causing any problems.

Is there some command that just disables a thing?
The only enable/disable I find is for tooltips.

I tried hiding the button, and setting its
object reference to nil, that sent focus to the button that was
pressed before that. Closing the window sent focus to the
previous button on the previous window.

but I believe this will do the same as hiding, just shifting focus to the next widget.
You can put ALL your buttons into a single group and disable everything in one swell foop with my_group:deactivate()

Or, you can try to force focus to a dummy widget.
Reference URL's