reading more than 2 keys at once from a keyboard?

Started by
12 comments, last by TheAdmiral 17 years, 7 months ago
As somebody noticed above, you could use array of booleans, and handle WM_KEYDOWN and WM_KEYUP messages setting wParam in array. The drawback of this aproach is that if you hold one key, your keyboard buffer gets full and pc starts to beep. I think that using Direct Input you'll get what you want. You can define how much key presses you would like to check at once, and everything forks fine.

[Edited by - streamer on September 6, 2006 2:38:22 AM]
Advertisement
Quote:Original post by streamer
As somebody noticed above, you could use array of booleans, and handle WM_KEYDOWN and WM_KEYUP messages setting wParam in array. The drawback of this aproach is that if you hold one key, your keyboard buffer gets full and pc starts to beep. I think that using Direct Input you'll get what you want. You can define how much key presses you would like to check at once, and everything forks fine.

No such luck. This is exactly what GetAsyncKeyState does, but it still doesn't address the hardware problem. Just like Sneftel said, if you are holding down a few keys so as to saturate the keyboard matrix and you press another key, the keyboard has no means of communicating the keypress to the system, so the motherboard never sees it, the driver never sees it, the operating system never sees it: There's no way your WndProc is going to receive a WM_KEYDOWN message.

The same goes for DirectInput. Using DX gives you no more command over the keyboard than using Win32, unfortunately.

I'm afraid you'll have to live with it, and make the best use of modifier keys as you can. ...Or create your own keyboard to ship with the game [rolleyes].

Regards
Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Quote:Original post by TheAdmiral

The same goes for DirectInput. Using DX gives you no more command over the keyboard than using Win32, unfortunately.



Unfortunately I must disagree. At the moment I'm developing a game for 4 players, and game has option that all 4 players play game at once on ONE keyboard. I tried moving diagonal left, while shooting with 4 players at once. That's diagonal movement = 2 keys + shooting = 1 key * 4 players , that is 12 key at once was held down, and everything moved, shot, there was no beeps, so everything absolutely worked fine and all that with Direct Input.
Quote:Original post by streamer
At the moment ... everything absolutely worked fine and all that with Direct Input.

Well that's great. Do what you need, so long as it works.
But Microsoft officially recommend that Win32 be used for mouse & keyboard input, with DirectInput being reserved for gaming devices. I'd guess they have a reason for doing so. I've heard that the DirectInput keyboard simply wraps Win32 functionality on global WM_KEYUP/DOWN messages, but I can't confirm this. No matter which wraps which, I doubt the performance difference is measurably significant, so there's no need for anyone to go back and change their code.

Regards
Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.

This topic is closed to new replies.

Advertisement