fix numpad behavior: movement keys are no longer triggered with numlock on

This commit is contained in:
mniip 2014-02-27 20:39:16 +04:00
parent d59253cfc7
commit 43bff37279
4 changed files with 32 additions and 8 deletions

View File

@ -414,6 +414,27 @@ std::map<std::string, std::string> readArguments(int argc, char * argv[])
return arguments;
}
SDLKey MapNumpad(SDLKey key)
{
switch(key)
{
case KEY_NUM_UP:
return KEY_UP;
case KEY_NUM_DOWN:
return KEY_DOWN;
case KEY_NUM_RIGHT:
return KEY_RIGHT;
case KEY_NUM_LEFT:
return KEY_LEFT;
case KEY_NUM_HOME:
return KEY_HOME;
case KEY_NUM_END:
return KEY_END;
default:
return key;
}
}
int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0;
unsigned int lastTick = 0;
float fps = 0, delta = 1.0f, inputScale = 1.0f;
@ -422,6 +443,9 @@ 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.sym = MapNumpad(event.key.keysym.sym);
switch (event.type)
{
case SDL_QUIT:

View File

@ -41,10 +41,10 @@ void ConsoleView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, b
commandField->SetText("");
commandField->SetDisplayText("");
break;
case KEY_DOWN: case KEY_NUM_DOWN:
case KEY_DOWN:
c->NextCommand();
break;
case KEY_UP: case KEY_NUM_UP:
case KEY_UP:
c->PreviousCommand();
break;
default:

View File

@ -229,9 +229,9 @@ void PropertyWindow::OnDraw()
void PropertyWindow::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
if (key == KEY_UP || key == KEY_NUM_UP)
if (key == KEY_UP)
property->SetOption(property->GetOption().second-1);
else if (key == KEY_DOWN || key == KEY_NUM_DOWN)
else if (key == KEY_DOWN)
property->SetOption(property->GetOption().second+1);
}

View File

@ -342,20 +342,20 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
{
switch(key)
{
case KEY_HOME: case KEY_NUM_HOME:
case KEY_HOME:
cursor = 0;
ClearSelection();
break;
case KEY_END: case KEY_NUM_END:
case KEY_END:
cursor = backingText.length();
ClearSelection();
break;
case KEY_LEFT: case KEY_NUM_LEFT:
case KEY_LEFT:
if(cursor > 0)
cursor--;
ClearSelection();
break;
case KEY_RIGHT: case KEY_NUM_RIGHT:
case KEY_RIGHT:
if(cursor < backingText.length())
cursor++;
ClearSelection();