Sign in to follow this  
Ebola0001

reading more than 2 keys at once from a keyboard?

Recommended Posts

I was just wondering if it’s possible to read more than 2 at once, I’m working on a full 6d freedom game and it would be much easier to control if they weren’t limited to pressing only 2 keys at once, since I have keys set for: Yaw+ Yaw- Pitch+ Pitch- Roll+ Roll- X+ (Left) X- (Right) Y+ (Up) Y- (Down) Z+ (Forward) Z- (Back) I easily find myself trying to rotate in 2 directions, and move also and my computer doesn't recognize any keys after the first 2 and if you hold down 3 or more, it complains and beeps at you. :)

Share this post


Link to post
Share on other sites
Yep, there's nothing software-related about not being able to press more than 2 or 3 keys at a time. Most keyboards use a system of electrical interconnects which simply can't do more than that at a time. Moreover, each keyboard is different WRT which key combinations it will and won't recognize. Bottom line: modifier keys (ctrl, shift, alt) aside, don't count on users being able to press more than two keys simultaneously.

Share this post


Link to post
Share on other sites
You could fix the problem by keeping track of up and down key events. Have an array of booleans and when key (x) is pressed down set array[x] = true when key (x) goes up set array[x] = false
Every frame when you update your code you could check the array to see if key (x) is down and take action depending on the function of key (x)

Share this post


Link to post
Share on other sites
Quote:
Original post by SuperNerd
You could fix the problem by keeping track of up and down key events. Have an array of booleans and when key (x) is pressed down set array[x] = true when key (x) goes up set array[x] = false
Every frame when you update your code you could check the array to see if key (x) is down and take action depending on the function of key (x)

No. Again, this is not a software issue. The keyboard literally WILL NOT NOTICE that the extra key was pressed.

Share this post


Link to post
Share on other sites
Yes I never understood why no one came out with a USB keyboard that used individual key switches instead of the normal electrical matrix way. That way you could get any input sent to the keyboard into the computer. It may be a little less efficient, but with mice sending 2000dpi images to be read every millisecond or whatever I think it should be possible

Share this post


Link to post
Share on other sites
you could use a
789
4 6
123
setup for 4 dimensions and separate keys for other directions
or you could make it so only a key press (not holding down the key) will make you move in that direction, so repeated presses will accelerate/decelerate.
Or of course let the mouse have a part in movement.
Seems like you dont have many other options if the keyboard will only recognize 2 held down at once ><

Share this post


Link to post
Share on other sites
Quote:
Original post by neonic
Yes I never understood why no one came out with a USB keyboard that used individual key switches instead of the normal electrical matrix way. That way you could get any input sent to the keyboard into the computer. It may be a little less efficient, but with mice sending 2000dpi images to be read every millisecond or whatever I think it should be possible


It's simply a cost issue. Having 100 pins on your controller chip is expensive. Having 20 pins is cheap (a 10x10 matrix). Having 20 pins and some kind of of polling system is inaccurate.

Also, 2000dpi is reasonably low resolution when you're capturing such a tiny area.

Share this post


Link to post
Share on other sites
The ZBoard supposedly allows up to 7 simultaneous key presses. Seeing as they claim "up to" 7 I'm not sure it would work, but unlike most keyboards it at least might.

The Razer Tarantula is currently unreleased (I've unreliably heard Sept 7), but claims "The Razer Tarantula's Anti-Ghosting Capability allows for unlimited simultaneous keystrokes without jamming."

Also some older (pre-PS2) keyboards did not face this problem.

A historical note: Way back in those pre-PS2 days PC games commonly allowed multiple players to share a single keyboard. This trend drastically decreased in popularity as access to LANs became more common.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this