Key works fine, unless I hold down 3 at once?

BlitzMax Forums/BlitzMax Programming/Key works fine, unless I hold down 3 at once?

WERDNA(Posted 2010) [#1]
Hey folks!

I've got kind of a weird problem, but something I seem to remember
having long ago with Blitz3D.

I have a function in my game that moves the player like so, using
customized global variables to hold the key codes so I can easily
swap out what key does what.

If KeyDown(MOVELEFT)
P.x = P.x - P.MSpd
End If

If KeyDown(MOVERIGHT)
P.x = P.x + P.MSpd
End If


If KeyDown(MOVEUP)
P.y = P.y - P.MSpd
End If

If KeyDown(MOVEDOWN)
P.y = P.y + P.MSpd
End If

Then later on in the code, in a loop that handles bullets I have this
piece of code

If ChargeCount >= ChargeMax
If KeyDown(ACTIONBUTTON)
FrameCount = 0
Local yo#
If Dir = 1
yo# = y-ImageHeight(image)/2-ImageHeight(Projectile[SubTyp])/2
ElseIf Dir = 2
yo# = y+ImageHeight(image)/2+ImageHeight(Projectile[SubTyp])/2
End If
MakeBullet(x#,yo#,0,0,8,0,Projectile[SubTyp],1,0,0,0,1,1,1)
ChargeCount = 0
End If
End If

All of the above works great. however when I hold down
the ACTIONBUTTON to fire a bullet, and try to move diagonally up
and left while firing, I won't be able to move diagonally. I'll move
either straight up while firing, or move straight left while firing, but
not diagonally.

The really strange part though, is that I can move in all other directions
just fine(Including the other diagonals) while I'm firing. Just not left\up.


What might be causing this?

Thanks!


*(Posted 2010) [#2]
This could be down to your keyboard, its a old PC problem (back from the XT era) three keys was the maximum you were allowed to press at any one time.

This doesnt help you much but if you code around the limitation then it will help sell your games to the masses in the future. For instance you dont need to move up and down at the same time or left and right, you could have either up or down, left or right, and fire.


xlsior(Posted 2010) [#3]
This could be down to your keyboard, its a old PC problem (back from the XT era) three keys was the maximum you were allowed to press at any one time.


Actually, it varies depending on *which* keys you press: there are certain keys that lock out others, due to shared address lines on the keyboard controller board.

Certain keys can lock eachother out if you just have two pressed, but there are other combinations where it can see 7 distinct keys that still work together -- but certain keys combinations are always going to fail on the majority of keyboards... So it really sucks if it happens to a combination that you need, because there is NO workaround for this -- it's a physical limitation of the keyboard hardware.

Some USB keyboards may not exhibit the problem, but identical code on other USB keyboards will run into the lock-ups, and pretty much all PS/2 and AT keyboards will have lock-out issues.


WERDNA(Posted 2010) [#4]
crap.

I don't often swear, but this is a situation where it's called for.

I really need the player to be able to move diagonally while firing.
I'll use Mouse controls, but I really do want the keyboard to be an option as well...

I'll see what I can do to code around this interesting little issue, but
is there a list somewhere of which keys lock out other keys? Or at the
very least the most common keys that lock each other out on assorted
keyboards?

I'll try switching to WASD instead of the arrow keys and see what happens.

Thanks!


Gabriel(Posted 2010) [#5]
Typically, you would allow players to define their own keys, so that they may choose a set of keys which do not clash on their own keyboard.


xlsior(Posted 2010) [#6]
I really need the player to be able to move diagonally while firing.


You may want to check WASD or some of the other combos and see if you have your lock-out problem there as well.

Here are some common alternate layouts:
http://en.wikipedia.org/wiki/Arrow_keys


and of course, there's always the numerical keypad where you can use the 7-9-1-3 for diagonal travel... Although a big drawback of that is that it's very impractical for laptop users that don't have a dedicated numerical keypad.

Like Gabriel suggests, ideally you let the player choose their own layout, preferably with some semi-standard layouts to pick from in addition to the ability to pick their own.


GIB3D(Posted 2010) [#7]
With your game you're only pressing up to 3 keys at any one time anyways. Try using something like this

P.x = P.x + (KeyDown(MOVERIGHT) - KeyDown(MOVELEFT))
P.y = P.y + (KeyDown(MOVEDOWN) - KeyDown(MOVEUP))



xlsior(Posted 2010) [#8]
Some combination of just 2 keys can lock eachother out too.


WERDNA(Posted 2010) [#9]
The game is already set up so that player's can easily define their own keys ;)

I just want to plan ahead, for if they pick a key combination that doesn't work.

Thanks for the list xlsior, that should really help out!


@GIB3D
Intriguing! I'll give that a try.


Thanks everyone!

One of those at least should fix the problem ;)