Jump to content
  • Advertisement
Sign in to follow this  
Myke111

wxWidgets Key-Repeat Delay

This topic is 3785 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

Hey Guys, I wonna use wxWidgets in combination with OpenGL to implement some 3D Rendering stuff. I need some ego-shooter like interaction with the 3D scene and therefor i need to process the keyboard to move around the scene. Unfortunately i have no idea of how to disable the delay that occurs when pressing and holding a key. There are two ways to handle the problem i guess: 1) Disable key-repeat function completely and do the rendering stuff on Idle Events. Then i could use flags to remember which key was pressed. 2) Just disable the delay when holding a key and doing the rendering stuff on Paint Events. Then i could do normal rendering stuff on Paint Events and call the rendering stuff on KeyEvents. I would certainly prefer the second approach, since it would use less CPU power. ANY suggestions would be welcome.

Share this post


Link to post
Share on other sites
Advertisement
I have no idea why you would expect the second approach to use "less CPU power", or in fact why it would be a concern at all. Checking what keys are pressed only takes time when you actually perform the check, which should be once per main game loop. You'll be rendering the entire scene at least that often, and even drawing a single triangle is much more work than checking the keyboard state.

I don't know what you mean by "do normal rendering stuff on Paint Events and call the rendering stuff on KeyEvents", but you should never respond to a key event by just drawing something immediately. Separate the updating logic from the rendering logic: drawing stuff should not affect the game state, and changing the game state should not involve drawing anything. That way, you are free to draw whenever you want (or are requested to). Similarly, make as few changes as possible in response to the key press; let the next "physics update" determine what happens as a result.

In practice, this means:

- Disable key-repeat function completely.
- On key events, set some flags (note that things like "velocity" or "acceleration" may count as "flags", depending on how your game physics are supposed to work.)
- On idle events, do physics (e.g. for a space game with realistic thrusters, the key presses set acceleration to some exact value, and on the physics update, you add acceleration to current velocity, and then current velocity to current position - numerical integration).
- On paint events, draw whatever things currently look like (according to what the physics calculated).

Share this post


Link to post
Share on other sites
Thanks for your reply.

Quote:
Original post by Zahlman
I have no idea why you would expect the second approach to use "less CPU power"...

You assume that i'm programming a game, which is no true. I'm actually drawing a static scene without any physics. I assumed that wxWidgets calls the paint-event just when it is needed: eg window resizing. This means that calling the render function during idle-events would cause my program to render the whole scene even when nothing changed. This further means that rendering the scene on paint-events just renders it when it is required. So if i change the scene during idle-events (by taking into account pressed keys) i have to render the scene.

the proper question would have been:
does anybode know HOW to disable the key-repeat as a whole or how to disable the key-repeat-delay in wxWidgets.

Share this post


Link to post
Share on other sites
This isn't really the answer you were looking for, but it helped me get around a similar situation. Instead of using keydown events, you can call wxGetKeyState( wxKeyCode) at any point in your main loop. If you want to use keycodes for arrow keys, etc, its WXK_UP, WXK_PAGEDOWN, etc. If you want to use it for ASCII keys, you'll have to do something like wxGetKeyState( (wxKeyCode) 'A');

It does not suffer from the delay problems, but you have to check it every frame.

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!