Louring
Lionel Stephen 2 posts
|
#11629
Struggling with keyboard input (Window Messages) 1 year ago Edited by Lionel Stephen on April 8, 2017, 12:18 a.m.
Hello,
I'm new to the series and brand new to the forum, but I'm loving the adventure so far... However I don't like copying without really understanding and am always searching deeper into how things work. I'm following the series but every time I don't understand something I start implementing it myself, usually with really ugly code, but I enjoy learning how it all works. However as you would expect I've struggled with everything and only made it to episode 9 or so... just finished implementing DirectSound in pure c... I hate COM xD Anyway, my issue is window messages. I've tried to use WASD and Arrow keys for movement, but in a simple test, Arrows key end up sending thousands of messages a second. While Characters send messages as you would expect ( a pause, then repeat is activated ). -- This is the code I'm using for testing at the moment:
-- I then print out the variables: printf("> arrow : %d \n> letter : %d \n", arrow, letter); -- The output after holding down each key for (roughly) 2 seconds is this: (both variables are initialised to zero) arrow : 621096 letter : 31 If my keyboard isn't the culprit then I suggest I have to manipulate the repeat-count of the messages, or process a certain amount of messages per frame This is probably normal behaviour but I can't find any reference to it (that's why I'm making a post) I've tried moving until the WM_KEYUP and WM_SYSKEYUP messages are processed and I get better movement, the difference in messages is still huge and it feels wrong and I don't understand it :-( If someone knows what's going on here please let me know. By the way this is my first forum post ever, I hope it's in the right place and such Thankyou |
mmozeiko
Mārtiņš Možeiko 1638 posts
1 project
|
#11631
Struggling with keyboard input (Window Messages) 1 year ago Edited by Mārtiņš Možeiko on April 8, 2017, 7:54 a.m.
Are you sure you are not processing same message multiple times? Keyrepeat usually is far less than 621096 keydown messages per 2 seconds.
Are you sure you initialized arrow variable to 0 and its type is int (because of %d) ? I just tried counting VK_LEFT's for wParam on WM_KEYDOWN message in my code and I get ~40 per 2 seconds on my machine. So error must be in some other part of your code. Btw, instead of case 0x41 you can simply write case 'A'. That will save you some typing for a comment. |
Louring
Lionel Stephen 2 posts
|
#11632
Struggling with keyboard input (Window Messages) 1 year ago
Wow, I can't believe I'm so stupid, such a little thing giving me so much trouble :/
I had my Translate and Dispatch functions outside the PeekMessage if statement...
I just changed it, and get expected results. Thank you very much Mārtiņš Možeiko. |
ripple
4 posts
|
#11639
Struggling with keyboard input (Window Messages) 1 year ago
You are also missing the check for repeated key presses
|