123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|378|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Basic Basement -> Keyboard Control Conundrum

Posted : Saturday, 11 August 2018, 10:11
Charles

Keyboard Control Conundrum


Hi all. I'm setting up keyboard controls for a 2D game with standard 8-directional movement, using PureBasic. I have these kinds of checks:

If Right key is pressed, and not Down, Left or Up, move East

If Right and Down keys are pressed, and not Left or Up, move Southeast

Etc.

If more than two directional keys are pressed at the same time, nothing should happen. And in fact nothing happens if I press Up-Right-Down or Right-Down-Left (it doesn't matter in what order the keys are actually pressed, it will stop movement if all three are pressed simultaneously).

However, if I press Down-Left-Up, my character moves in the Southwest direction. And if I press Left-Up-Right, he moves Northwest.

That's for the directional arrow keys. If I change the mappings to WASD, then Left-Up-Right and Right-Down-Left stop, but the other two combinations don't.

I've had other unexpected results with multiple key presses, while gamepad controls work fine.

Any ideas?
Posted : Saturday, 11 August 2018, 13:10
spinal
My guess is that if you hit a key first, then the other keys, your code is activating that instruction before the other keys are pressed.

-=-=-
Check out my excellent homepage!
Posted : Saturday, 11 August 2018, 13:30
Jayenkai
Either that, or you’re hitting a physical keyboard limit.
Due to the way all those 100+ buttons all hook up via a tiny cable, only certain combinations of buttons will physically work. This has been a known limitation for a long long long time, and isn’t going away any time soon. As a result, you should never expect 3 nearby keys to be pressed in combination, as in most cases, the technology simply cannot support it.

-=-=-
''Load, Next List!''
Posted : Saturday, 11 August 2018, 14:34
Charles
Thanks for the replies. I've been doing some reading about keyboards, and I think I am, in fact, hitting that limit. My game has a strafing button as well, and if I map that to a key close to WASD, it becomes impossible to move diagonally.

Thanks goodness for gamepads!