Skip to content

Commit

Permalink
An ugly fix for numpad, since it seems event.key.keysym.mod isn't ent…
Browse files Browse the repository at this point in the history
…irely reliable for some unknown reason

Partial revert of 7ce9907
  • Loading branch information
jacksonmj committed Mar 12, 2014
1 parent 1ca63b3 commit c6d6011
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/PowderToySDL.cpp
Expand Up @@ -450,15 +450,20 @@ float currentWidth, currentHeight;
void EventProcess(SDL_Event event)
{
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
if ((!(event.key.keysym.mod&KEY_MOD_NUM)) ^ (!!(event.key.keysym.mod&KEY_MOD_SHIFT)))
{
if (event.key.keysym.unicode==0)
{
// If unicode is zero, this could be a numpad key with numlock off, or numlock on and shift on (unicode is set to 0 by SDL or the OS in these circumstances. If numlock is on, unicode is the relevant digit character).
// For some unknown reason, event.key.keysym.mod seems to be unreliable on some computers (keysum.mod&KEY_MOD_NUM is opposite to the actual value), so check keysym.unicode instead.
// Note: unicode is always zero for SDL_KEYUP events, so this translation won't always work properly for keyup events.
SDLKey newKey = MapNumpad(event.key.keysym.sym);
if (newKey != event.key.keysym.sym)
{
event.key.keysym.sym = newKey;
event.key.keysym.unicode = 0;
}
}
}
switch (event.type)
{
case SDL_QUIT:
Expand Down
7 changes: 2 additions & 5 deletions src/gui/interface/Textbox.cpp
Expand Up @@ -302,11 +302,8 @@ void Textbox::Tick(float dt)

void Textbox::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
if (keyDown == key)
{
keyDown = 0;
characterDown = 0;
}
keyDown = 0;
characterDown = 0;
}

void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
Expand Down

0 comments on commit c6d6011

Please sign in to comment.