Skip to content

Commit

Permalink
- additional bugfixes for keyboard entry in sdl2
Browse files Browse the repository at this point in the history
  • Loading branch information
softcoder committed Oct 9, 2015
1 parent 6707343 commit 4559862
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
16 changes: 9 additions & 7 deletions source/glest_game/menu/menu_state_keysetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,11 @@ void MenuStateKeysetup::keyDown(SDL_KeyboardEvent key) {
//printf("\nkeyDown [%d]\n",hotkeyChar);

string keyName = "";
if(hotkeyChar > SDLK_UNKNOWN && hotkeyChar < SDL_NUM_SCANCODES) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] keyName [%s] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),hotkeyChar,key.keysym.sym);
keyName = SDL_GetKeyName(hotkeyChar);
}
//if(hotkeyChar > SDLK_UNKNOWN && hotkeyChar < SDL_NUM_SCANCODES) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] keyName [%s] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),hotkeyChar,key.keysym.sym);
keyName = SDL_GetKeyName(hotkeyChar);
//printf ("In [%s::%s Line: %d] keyName [%s] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),hotkeyChar,key.keysym.sym);
//}
//key = hotkeyChar;

if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] keyName [%s] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),hotkeyChar,key.keysym.sym);
Expand Down Expand Up @@ -524,6 +525,7 @@ void MenuStateKeysetup::keyDown(SDL_KeyboardEvent key) {
char szBuf[8096] = "";
snprintf(szBuf,8096," %s [%s][%d][%d][%d]",keyName.c_str(),utfStr,key.keysym.sym,hotkeyChar,key.keysym.mod);
labelTestValue.setText(szBuf);
//printf ("In [%s::%s Line: %d] szBuf [%s]\n",__FILE__,__FUNCTION__,__LINE__,szBuf);

delete [] utfStr;

Expand All @@ -541,9 +543,9 @@ void MenuStateKeysetup::keyUp(SDL_KeyboardEvent key) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,hotkeyChar,key.keysym.sym);

string keyName = "";
if(hotkeyChar > SDLK_UNKNOWN && hotkeyChar < SDL_NUM_SCANCODES) {
keyName = SDL_GetKeyName(hotkeyChar);
}
//if(hotkeyChar > SDLK_UNKNOWN && hotkeyChar < SDL_NUM_SCANCODES) {
keyName = SDL_GetKeyName(hotkeyChar);
//}
key.keysym.sym = hotkeyChar;

if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] keyName [%s] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),hotkeyChar,key.keysym.sym);
Expand Down
32 changes: 20 additions & 12 deletions source/shared_lib/sources/platform/sdl/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ static bool isUnprintableChar(SDL_keysym key) {
return true;
default:
// U+0000 to U+001F are control characters
return (key.sym < 0x20);
/* Don't post text events for unprintable characters */
if (key.sym > 127) {
return true;
}
if(key.sym < 0x20) {
return true;
}
//printf("isUnprintableChar returns false for [%d]\n",key.sym);
return false;
}
}

Expand Down Expand Up @@ -1067,22 +1075,22 @@ vector<int> extractKeyPressedUnicodeLength(string text) {
SDL_Keycode extractKeyPressed(SDL_KeyboardEvent input) {
SDL_Keycode c = SDLK_UNKNOWN;
//if(input.keysym.unicode > 0 && input.keysym.unicode < 0x80) {
if(input.keysym.sym > 0) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] input.keysym.sym = %d input.keysym.mod = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,input.keysym.sym,input.keysym.mod);
//if(input.keysym.sym > 0) {
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] input.keysym.sym = %d input.keysym.mod = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,input.keysym.sym,input.keysym.mod);

c = input.keysym.sym;
// c = input.keysym.sym;
// if(c <= SDLK_UNKNOWN || c >= SDLK_LAST) {
// c = SDLKey(c & 0xFF);
// }

//c = toupper(c);

if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] #1 (c & 0xFF) [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(c & 0xFF));
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] #1 (c & 0xFF) [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(c & 0xFF));
}
if(c <= SDLK_UNKNOWN) {
c = input.keysym.sym;
}
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] #1 (c & 0xFF) [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(c & 0xFF));
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] #1 (c & 0xFF) [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(c & 0xFF));
//}
//if(c <= SDLK_UNKNOWN) {
c = input.keysym.sym;
//}

if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %u] c = [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c);

Expand All @@ -1093,8 +1101,8 @@ SDL_Keycode extractKeyPressed(SDL_KeyboardEvent input) {
string pressKeyName = SDL_GetKeyName(c);
//string inputKeyName = SDL_GetKeyName(input.keysym.sym);

//printf ("PRESS pressed key [%d - %s] input.keysym.sym [%d] input.keysym.unicode [%d] mod = %d\n",
// c,pressKeyName.c_str(),input.keysym.sym,input.keysym.unicode,input.keysym.mod);
// printf ("PRESS pressed key [%d - %s] input.keysym.sym [%d] mod = %d\n",
// c,pressKeyName.c_str(),input.keysym.sym,input.keysym.mod);

if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] pressed key [%d - %s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c,pressKeyName.c_str());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] pressed key [%d - %s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c,pressKeyName.c_str());
Expand Down

0 comments on commit 4559862

Please sign in to comment.