Another SDL Input question

closed account (zwA4jE8b)
The SDLK_SPACE makes the character jump.
While pressing the combinations " up + right" or " down + right" or "down + left" I can push 'space' and jump. However when I am pressing the combination "up + left" pressing 'space' does nothing.

Can anyone spot why this is? It is only that one combination of keys that does not work. Perhaps it depends on the keyboard?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void player_one::handle_input(Uint8* keystate)
{
	if(keystate[SDLK_SPACE] && !jumping)
	{
		y_old = position.y_pos;
		y_vel = -400;
		jumping = true;
	}

	if(!jumping)
	{
		if(keystate[SDLK_UP] && !keystate[SDLK_DOWN])
			y_vel = -100;
		else if(keystate[SDLK_DOWN] && !keystate[SDLK_UP])
			y_vel = 100;
		else
			y_vel = 0;
	}

	if(keystate[SDLK_LEFT] && !keystate[SDLK_RIGHT])
		x_vel = -100;
	else if(keystate[SDLK_RIGHT] && !keystate[SDLK_LEFT])
		x_vel = 100;
	else
		x_vel = 0;
}
Perhaps it depends on the keyboard?


This is my bet. Many low end keyboards do not recognize multiple keys being pressed at once. For casual typing, you never need to press 3 keys simultaneously, so they don't bother supporting it. More expensive / game keyboards are usually better about it.

Some keys are designed to work with multiple key presses though because their primary use is to be in key combos. Try using Shift, Ctrl, or Alt instead of Space and see if it works.


... but of course, all keys in all games should be user configurable anyway ;P
closed account (zwA4jE8b)
It does seem to be the case. I changed 's' to be jump and the arrow keys still move. it seems that most/all keyboards will take 3 or more simultaneous keypresses when only 2 non character keys are pressed in conjunction with characters. huh.

I did try alt and ctrl but received the same result. That is how I arrived at my conclusion.
Last edited on
Topic archived. No new replies allowed.