Jump to content
  • Advertisement
Sign in to follow this  
BerwynIrish

Python - clearing events?

This topic is 4300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a program in Python that binds keypress events to a function. Inside this function, if the key pressed is a certain key, then I use os.system() to run another program. This program can take up to 15 seconds before the user sees anything different on the screen, during which time the user might assume that the keypress didn't register and so hit the key again. If this happens, then when the program called from os.system() exits, my program sees the second keypress and passes it along to my binded method, resulting in another os.system() call. Is there a command to clear keypresses or something similar which I can use to prevent os.system() from executing a second time? I've tried setting a flag as the first thing in the block for this key which will cause my binded method to exit right away if the flag is set. I've also tried using the unbind method to disable my key processing method and then rebinding when the called program terminates. Niether of these work.

Share this post


Link to post
Share on other sites
Advertisement
There should be a way to flush the input buffer; you might try sys.stdin.flush(), but from the little poking around I did on google it looks like that doesn't actually do anything. You might also try storing keypresses in a list when they are received rather than sending them directly to your function; then in your main loop you can iterate through your list and send each keypress value in the list to the appropriate function. After returning from the other program you would just clear the input list to get rid of the unwanted keypresses.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!