Why do keys behave differently?

Hello.
To begin, I would like to apologize for my English.
So sorry.

I write my first SDL game and I have problem with player movement.
This is my code:

if ((Game::event.type == SDL_KEYDOWN || Game::event.type == SDL_CONTROLLERBUTTONDOWN) && Game::pause == false) {
	if (Game::event.key.keysym.sym == SDLK_w || Game::event.key.keysym.sym == SDLK_UP || Game::event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP) {
		transform->position.y -= 32;
	}
	else if (Game::event.key.keysym.sym == SDLK_s || Game::event.key.keysym.sym == SDLK_DOWN || Game::event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) {
		transform->position.y += 32;
	}
	else if (Game::event.key.keysym.sym == SDLK_d || Game::event.key.keysym.sym == SDLK_RIGHT || Game::event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) {
		transform->position.x += 32;
	}
	else if (Game::event.key.keysym.sym == SDLK_a || Game::event.key.keysym.sym == SDLK_LEFT || Game::event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) {
		transform->position.x -= 32;
	}
}

But if I press, for example, W key the player move slowly than if I press up button. And if I press up button on my gamepad the player make move only once.
I can’t explain why buttons behave differently when they do the same thing.

  1. Don’t handle two unrelated event types at once. You’ll need separate cases for SDL_KEYDOWN and SDL_CONTROLLERBUTTONDOWN, because in your code it could happen that it’s SDL_CONTROLLERBUTTONDOWN but event.key.keysym.sym is still SDLK_w, for example - because SDL_Event is a union, so event.key and event.cbutton are at the same memory address
  2. I guess your problem is that you only handle this once when the button is pressed down, so it only moves once, until you release the button and press it again. For keyboard you’ll frequently get new keydown events due to key repeat, but AFAIK the repeat rate is system-specific, so it’s nothing you should rely on.
    What you should do is remember when the button is pressed down and then every 16 milliseconds (or whatever time interval) do transform->position.y -= 32; etc, until the button is released again.

And why movent is not same if I press W or UP key?
https://vimeo.com/342827040

because the keyboard has key repeat and the controller doesn’t

EDIT: oh you mean SDLK_UP vs SDLK_w ? could be that key is only repeated or at different rate for character keys? not sure

Oh okay… Thank you