keyboard delay

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
lostpencil
Posts: 17
Joined: Fri Dec 16, 2005 5:46 pm
Contact:

keyboard delay

Post by lostpencil »

I've been playing with Irrlicht a bit, specifically the Movement demo. I think I figured out how to get rid of keyboard delay if anyone is interested. If I'm missing a paradigm or concept dealing with keyboard input please let me know. This, of course, will only work in Windows:

For clarity and ease of use I declared the following variables globablly in main.cpp (of the movement demo):

Code: Select all

// a couple of structures to hold the original and updated filterkey info
//
FILTERKEYS original_FilterKeys, irr_FilterKeys;
Then anywhere before the game loop place the following code:

Code: Select all

// save the user's original filterkey settings
//
ZeroMemory(&original_FilterKeys, sizeof(FILTERKEYS));
original_FilterKeys.cbSize = sizeof(FILTERKEYS);
SystemParametersInfo(SPI_GETFILTERKEYS, sizeof(FILTERKEYS), &original_FilterKeys, 0);

// set the delay values so we get 'instant' response on held keys
//
ZeroMemory(&irr_FilterKeys, sizeof(FILTERKEYS));
irr_FilterKeys.cbSize = sizeof(FILTERKEYS);
irr_FilterKeys.iDelayMSec = 1;
irr_FilterKeys.iWaitMSec = 1;
irr_FilterKeys.iRepeatMSec = 1;
irr_FilterKeys.iBounceMSec = 0;
irr_FilterKeys.dwFlags = FKF_FILTERKEYSON;
SystemParametersInfo(SPI_SETFILTERKEYS,	sizeof(FILTERKEYS), &irr_FilterKeys, 0);
Then, just as you are leaving the game, make sure you restore the keyfilter settings using this:

Code: Select all

// restore keyfilter settings
//
SystemParametersInfo(SPI_SETFILTERKEYS,	sizeof(FILTERKEYS), &original_FilterKeys, 0);
Cheers,
Paul Mikulecky
Lost Pencil Animation Studios Inc.
http://www.lostpencil.com

"The art of character animation is to try
to catch lightning in a bottle.... one volt
at a time." Brad Bird
Guest

Post by Guest »

Code: Select all

error C2146: syntax error : missing ';' before identifier 'original_FilterKeys'
error C2501: 'FILTERKEYS' : missing storage-class or type specifiers
fatal error C1004: unexpected end of file found
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

hmm doing this would make it hard to type in any text-boxes and stuff in your gui.
keless's 'bool keys' is the best way to deal with keyboard input- a global array of booleans that keeps the state all keys, which is updated as keys are pressed down and released:
http://www.irrforge.org/index.php/Keybo ... keys.5B.5D
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
lostpencil
Posts: 17
Joined: Fri Dec 16, 2005 5:46 pm
Contact:

Post by lostpencil »

Hey Bitplane,

Good point regarding the GUI. Since we know when the GUI is going to be enabled then we can re-enable the previous status of the filterkeys before the GUI is loaded. I did a quick test using the bool_keys setup, but I think the 'delay' before the keyboard repeat rate still evidences itself when you use that method.

As for the error... oops... you have to include this near your includes:

Code: Select all

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
Cheers,
Paul Mikulecky
Lost Pencil Animation Studios Inc.
http://www.lostpencil.com

"The art of character animation is to try
to catch lightning in a bottle.... one volt
at a time." Brad Bird
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

keyboard input goes like this-

Code: Select all

user presses key down
system waits for iWaitMSec
keypress event generated
system waits for iDelayMSec
while (key is pressed) {
  keypress event generated
  system waits for iRepeatMSec
}
user released key
key-up event generated
wait for iBounceMSec before accepting the same key again
iWaitMSec and iBounceMSec are the only ones that affect bool keys, and I always thought they were 0 or very small by default unless you have accessability options turned on (haven't checked tho). does the keyboard delay happen in the fps cam on your machine? bool keys seems smooth enough here
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
lostpencil
Posts: 17
Joined: Fri Dec 16, 2005 5:46 pm
Contact:

Post by lostpencil »

Nice summary of keyevents. The delay no longer occurs with bool keys and I think I figured out what I originally did wrong when implementing bool keys.

The problem, I think, occured because in the wiki 'example code' after the explanation, the key checking is placed in the event handler. When I do that, it exhibits the delay behavior (similar to holding a key down in notepad). When I put the checking, the "if(keys[irr::KEY_KEY_W])", in the game loop then the key detection is instantaneous (and depending on the frame rate, I get 50 or so hits when pressing down the 'w' key quickly).

Thanks for helping me get the concept straight!
Cheers,
Paul Mikulecky
Lost Pencil Animation Studios Inc.
http://www.lostpencil.com

"The art of character animation is to try
to catch lightning in a bottle.... one volt
at a time." Brad Bird
Post Reply