- bugfix for filtering out non printable keys

This commit is contained in:
Mark Vejvoda 2011-06-28 01:25:14 +00:00
parent 945c2aa66b
commit f5b15bd402
8 changed files with 73 additions and 11 deletions

View File

@ -113,7 +113,8 @@ void ChatManager::keyDown(SDL_KeyboardEvent key) {
if(isKeyPressed(SDLK_RETURN,key) == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym,key.keysym.sym);
SDL_keysym keystate = Window::getKeystate();
//SDL_keysym keystate = Window::getKeystate();
SDL_keysym keystate = key.keysym;
if(keystate.mod & (KMOD_LALT | KMOD_RALT)){
// alt+enter is ignored
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym,key.keysym.sym);
@ -185,7 +186,7 @@ void ChatManager::keyPress(SDL_KeyboardEvent c) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,c.keysym.sym,c.keysym.sym);
//space is the first meaningful code
SDLKey key = extractKeyPressed(c);
if(key >= SDLK_SPACE) {
if(isAllowedInputTextKey(key)) {
char szCharText[20]="";
sprintf(szCharText,"%c",key);
char *utfStr = String::ConvertToUTF8(&szCharText[0]);

View File

@ -777,7 +777,8 @@ void MainWindow::eventMouseWheel(int x, int y, int zDelta) {
void MainWindow::eventKeyDown(SDL_KeyboardEvent key) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym);
SDL_keysym keystate = Window::getKeystate();
//SDL_keysym keystate = Window::getKeystate();
SDL_keysym keystate = key.keysym;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c][%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key);

View File

@ -2146,6 +2146,7 @@ void MenuStateConnectedGame::keyPress(SDL_KeyboardEvent c) {
SDLKey key = extractKeyPressed(c);
//if((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') ||
// (c=='-') || (c=='(') || (c==')')) {
if(isAllowedInputTextKey(key)) {
if(activeInputLabel->getText().size() < maxTextSize) {
string text= activeInputLabel->getText();
@ -2161,7 +2162,7 @@ void MenuStateConnectedGame::keyPress(SDL_KeyboardEvent c) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
//}
}
}
}
}

View File

@ -2956,6 +2956,7 @@ void MenuStateCustomGame::keyPress(SDL_KeyboardEvent c) {
SDLKey key = extractKeyPressed(c);
//if((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') ||
// (c=='-') || (c=='(') || (c==')')) {
if(isAllowedInputTextKey(key)) {
if(activeInputLabel->getText().size() < maxTextSize) {
string text= activeInputLabel->getText();
//text.insert(text.end()-1, key);
@ -2973,7 +2974,7 @@ void MenuStateCustomGame::keyPress(SDL_KeyboardEvent c) {
lastSetChangedGameSettings = time(NULL);
}
}
//}
}
}
}
}

View File

@ -711,6 +711,7 @@ void MenuStateOptions::keyPress(SDL_KeyboardEvent c) {
// no master server breaks, and a russian translation with game switched to KOI-8p encoding? probably irc too.
// (use Shared::Platform::charSet in shared_lib/include/platform/sdl/gl_wrap.h ?)
//(c=='-')||(c=='(')||(c==')')){
if(isAllowedInputTextKey(key)) {
if(activeInputLabel->getText().size()<maxTextSize){
string text= activeInputLabel->getText();
//text.insert(text.end()-1, key);
@ -722,7 +723,7 @@ void MenuStateOptions::keyPress(SDL_KeyboardEvent c) {
activeInputLabel->setText(text);
}
//}
}
}
}
else {

View File

@ -226,7 +226,8 @@ void MenuStateRoot::keyDown(SDL_KeyboardEvent key) {
}
//else if(mainMessageBox.getEnabled() == true && key == vkReturn) {
else if(mainMessageBox.getEnabled() == true && isKeyPressed(SDLK_RETURN,key) == true) {
SDL_keysym keystate = Window::getKeystate();
//SDL_keysym keystate = Window::getKeystate();
SDL_keysym keystate = key.keysym;
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] keystate.mod [%d]\n",__FILE__,__FUNCTION__,__LINE__,keystate.mod);
//printf("---> keystate.mod [%d]\n",keystate.mod);

View File

@ -125,7 +125,7 @@ public:
static void setupGraphicsScreen(int depthBits=-1, int stencilBits=-1, bool hardware_acceleration=false, bool fullscreen_anti_aliasing=false);
static const bool getIsFullScreen() { return isFullScreen; }
static void setIsFullScreen(bool value) { isFullScreen = value; }
static SDL_keysym getKeystate() { return keystate; }
//static SDL_keysym getKeystate() { return keystate; }
Window();
virtual ~Window();
@ -197,7 +197,7 @@ private:
bool isKeyPressed(SDLKey compareKey, SDL_KeyboardEvent input);
SDLKey extractKeyPressed(SDL_KeyboardEvent input);
bool isAllowedInputTextKey(SDLKey key);
}}//end namespace

View File

@ -983,7 +983,7 @@ bool isKeyPressed(SDLKey compareKey, SDL_KeyboardEvent input) {
string pressKeyName = SDL_GetKeyName((SDLKey)c);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] compareKey [%d - %s] pressed key [%d - %s] result = %d\n",__FILE__,__FUNCTION__,__LINE__,compareKey,compareKeyName.c_str(),c,pressKeyName.c_str(),result);
//printf ("In [%s::%s Line: %d] compareKey [%d - %s] pressed key [%d - %s] result = %d\n",__FILE__,__FUNCTION__,__LINE__,compareKey,compareKeyName.c_str(),c,pressKeyName.c_str(),result);
//printf ("In [%s::%s Line: %d] pressed key [%d - %s] input.keysym.unicode [%d] mod = %d\n",__FILE__,__FUNCTION__,__LINE__,c,pressKeyName.c_str(),input.keysym.sym,input.keysym.unicode,input.keysym.mod);
return result;
}
@ -1011,9 +1011,65 @@ SDLKey extractKeyPressed(SDL_KeyboardEvent input) {
string inputKeyName = SDL_GetKeyName(input.keysym.sym);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] pressed key [%d - %s]\n",__FILE__,__FUNCTION__,__LINE__,c,pressKeyName.c_str());
//printf ("In [%s::%s Line: %d] pressed key [%d - %s] input [%d - %s] input.keysym.unicode [%d]\n",__FILE__,__FUNCTION__,__LINE__,c,pressKeyName.c_str(),input.keysym.sym,inputKeyName.c_str(),input.keysym.unicode);
//printf ("In [%s::%s Line: %d] pressed key [%d - %s] input [%d - %s] input.keysym.unicode [%d] mod = %d\n",__FILE__,__FUNCTION__,__LINE__,c,pressKeyName.c_str(),input.keysym.sym,inputKeyName.c_str(),input.keysym.unicode,input.keysym.mod);
return c;
}
bool isAllowedInputTextKey(SDLKey key) {
bool result = (
key != SDLK_DELETE &&
key != SDLK_BACKSPACE &&
key != SDLK_TAB &&
key != SDLK_CLEAR &&
key != SDLK_RETURN &&
key != SDLK_PAUSE &&
key != SDLK_UP &&
key != SDLK_DOWN &&
key != SDLK_RIGHT &&
key != SDLK_LEFT &&
key != SDLK_INSERT &&
key != SDLK_HOME &&
key != SDLK_END &&
key != SDLK_PAGEUP &&
key != SDLK_PAGEDOWN &&
key != SDLK_F1 &&
key != SDLK_F2 &&
key != SDLK_F3 &&
key != SDLK_F4 &&
key != SDLK_F5 &&
key != SDLK_F6 &&
key != SDLK_F7 &&
key != SDLK_F8 &&
key != SDLK_F9 &&
key != SDLK_F10 &&
key != SDLK_F11 &&
key != SDLK_F12 &&
key != SDLK_F13 &&
key != SDLK_F14 &&
key != SDLK_F15 &&
key != SDLK_NUMLOCK &&
key != SDLK_CAPSLOCK &&
key != SDLK_SCROLLOCK &&
key != SDLK_RSHIFT &&
key != SDLK_LSHIFT &&
key != SDLK_RCTRL &&
key != SDLK_LCTRL &&
key != SDLK_RALT &&
key != SDLK_LALT &&
key != SDLK_RMETA &&
key != SDLK_LMETA &&
key != SDLK_LSUPER &&
key != SDLK_RSUPER &&
key != SDLK_MODE &&
key != SDLK_HELP &&
key != SDLK_PRINT &&
key != SDLK_SYSREQ &&
key != SDLK_BREAK &&
key != SDLK_MENU &&
key != SDLK_POWER);
return result;
}
}}//end namespace