Question About SDL2 Keyboard Input

Hi,

I am currently updating my open-source cross-platform SDL2 video game now.

Is there anyway to optimize the following source code:?

if (input->KeyOnKeyboardPressedByUser == SDLK_a)
{
    if (input->ShiftKeyPressed == false)  data->HighScoresName[logic->GameMode][data->PlayerRankOnGameOver][data->NameInputArayIndex] = 'a';
    else  data->HighScoresName[logic->GameMode][data->PlayerRankOnGameOver][data->NameInputArayIndex] = 'A';
}
else if (input->KeyOnKeyboardPressedByUser == SDLK_b)
{
    if (input->ShiftKeyPressed == false)  data->HighScoresName[logic->GameMode][data->PlayerRankOnGameOver][data->NameInputArayIndex] = 'b';
    else  data->HighScoresName[logic->GameMode][data->PlayerRankOnGameOver][data->NameInputArayIndex] = 'B';
}
else if (input->KeyOnKeyboardPressedByUser == SDLK_c)
{
    if (input->ShiftKeyPressed == false)  data->HighScoresName[logic->GameMode][data->PlayerRankOnGameOver][data->NameInputArayIndex] = 'c';
    else  data->HighScoresName[logic->GameMode][data->PlayerRankOnGameOver][data->NameInputArayIndex] = 'C';
}
// ... d-z, 0-9

Let me know, thanks!

JeZxLee

Ok,

So I have the new below source code:

if (input->KeyOnKeyboardPressedByUser >= SDLK_a && input->KeyOnKeyboardPressedByUser <= SDLK_z)
{
    if (input->ShiftKeyPressed == false)  data->HighScoresName[logic->GameMode][data->PlayerRankOnGameOver][data->NameInputArayIndex] = input->KeyOnKeyboardPressedByUser;
    else  data->HighScoresName[logic->GameMode][data->PlayerRankOnGameOver][data->NameInputArayIndex] = input->KeyOnKeyboardPressedByUser;//Must be capital - How?
}

It works for lower case letters, but I don’t know how to make it work for capital letters(when [Shift] is pressed)

JeZxLee

Haven’t we told you about SDL_TEXTINPUT before?

Nevermind…I got it working:

if (input->KeyOnKeyboardPressedByUser >= SDLK_a && input->KeyOnKeyboardPressedByUser <= SDLK_z)
{
    if (input->ShiftKeyPressed == false)  data->HighScoresName[logic->GameMode][data->PlayerRankOnGameOver][data->NameInputArayIndex] = input->KeyOnKeyboardPressedByUser;
     else  data->HighScoresName[logic->GameMode][data->PlayerRankOnGameOver][data->NameInputArayIndex] = ( char(input->KeyOnKeyboardPressedByUser) - 32 );
}

Thanks!

JeZxLee