🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Get around Window's key repeat delay with Keyboard Hook

Started by
1 comment, last by _WeirdCat_ 2 years, 6 months ago

I'm making a console game in C++ and whenever I hold down a key it gets delayed before it repeats itself. I attached a keyboard hook to my console but I can't find a way to get around repeat delay. I've also tried making an invisible window with it's own message loop but I have to SetFocus() the invisible window to make it receive inputs.

Is there a way to attach a message loop to a console?

Can I use a keyboard hook to get around repeat delay?

I think I have to use bit 7 in the KBDLLHOOKSTRUCT to check if the key is pressed or not and act accordingly but I don't know how to do it. Some sample code would be greatly appreciated.

P.S. Yes, I've googled my problem and none of it seems to work. I've seen another question on this topic in gamedev.net but he uses a message loop along with WindowProc and I think it's a GUI window not console.

Advertisement

not sure what do you mean get around, but if it happens that it is repeating event when you don't want that i suggest you make your own keyboard handler where you store pressed keys in a list

if key is pressed run void AddKey( key )

if there is a repeat and the key is already marked as pressed you do not add it to list,

void AddKey(key)

{

if(key.pressed) return;

AddKeyToList(key);

}

now AddKey should be executed whenever you get keydown event

I can't really say nothing more cause handling keyboard is specific to a need you didn't describe

read this first

when key is pressed mark it as pressed when key is released mark it as notpressed

in main app loop

for( keyspressed)

dosth

This topic is closed to new replies.

Advertisement