Permalink
Browse files

An ugly fix for numpad, since it seems event.key.keysym.mod isn't ent…

…irely reliable for some unknown reason

Partial revert of 7ce9907
  • Loading branch information...
jacksonmj committed Mar 12, 2014
1 parent 1ca63b3 commit c6d60113375eada9e907bd71a79240de82126a83
Showing with 8 additions and 6 deletions.
  1. +6 −1 src/PowderToySDL.cpp
  2. +2 −5 src/gui/interface/Textbox.cpp
@@ -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:
@@ -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)

0 comments on commit c6d6011

Please sign in to comment.