Flush keys?

Monkey Forums/Monkey Programming/Flush keys?

Leo Santos(Posted 2011) [#1]
Is there a way to "flush keys" like it was possible in BlitzMax?

Here's a example:
I have a modal window that pops up when the player hits "escape". Once the window is on, though, it checks for escape again to turn itself off, but that check is performed on the same frame that called the window in the first place, so the window closes immediately after opening.

While I can see ways to work around that, none of them would be as clean as resetting the input stack, So... is there a way to do that in Monkey?

Thanks!


Perturbatio(Posted 2011) [#2]
looking at the source of mojo.input it *probably* wouldn't be hard to implement since the key states are simply stored in an array, this array could be zeroed on a call to flushkeys.


Leo Santos(Posted 2011) [#3]
Looking at mojo.input was my first impulse, but I didn't find any array I could access and clear. The only mention to KeyHit, for instance, is this:

Function KeyHit( key )
Return device.KeyHit( key )
End

The "device" object seems to be defined in non-Monkey code (as far as I can tell from the top of my noobness), hence my problem. Is there a way to access it through Monkey, in order to keep everything cross-platform?

Thanks!
Leo.


sknightly(Posted 2011) [#4]
Monkey automatically Flushes Keys before each OnUpdate.

From the Modules Reference:
The input module uses a 'polling' input model, meaning that your program must continually check (or 'poll') the state of input devices. Polling is usually performed during the OnUpdate phase of your program.


Leo Santos(Posted 2011) [#5]
That's very helpful to know!

Unfortunately, the problem I'm running into is that the newly created object (a popup window) checks for a key hit in the same "OnUpdate" that it was created, forcing me to use a key to open the popup window, then another key to close it - otherwise it opens and then closes on the same frame - which sucks.

I tried delaying that key check by one frame, but that caused other things to stop working properly :-(.... forcing Flush Keys on demand would really be a one line solution in this case.

Thanks!


Leo Santos(Posted 2011) [#6]
Oh, just to clarify, I'm using "autonomous" objects - each Entity manages itself. There's no centralized input manager, so polling for input may occur at different moments on the same Update loop.

Thanks!


Jesse(Posted 2011) [#7]
I don't know if this will work for you but I would create a global variable that stores the scape key hit at the beginning of the "OnUpdate" and clear the variable where you use it. that way you would only be able to use it once per "OnUpdate" cycle.