Skip to content

Commit

Permalink
Merge pull request #54 from rpaciorek/key_names
Browse files Browse the repository at this point in the history
fix getAsString for explicit converted keycodes
  • Loading branch information
Ybalrid authored Aug 13, 2019
2 parents dfe2cfd + aa5d89c commit 27c44b0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 62 deletions.
25 changes: 16 additions & 9 deletions includes/linux/LinuxKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ namespace OIS
if(keySym != NoSymbol)
{
//Check for explicit convert
OIS::KeyCode converted = convert(keySym);
if(converted != KC_UNASSIGNED)
return converted;

const auto result = keyConversionToOIS.find(keySym);
if(result != keyConversionToOIS.end())
return result->second;
::KeyCode xkc = XKeysymToKeycode(display, keySym);
if(xkc > 8)
return static_cast<KeyCode>(xkc - 8);
Expand All @@ -109,17 +109,24 @@ namespace OIS
{
if(kc == KC_UNASSIGNED)
return NoSymbol;


//Check for explicit convert
const auto result = keyConversionFromOIS.find(kc);
if(result != keyConversionFromOIS.end())
return result->second;

::KeyCode xkc = kc + 8;

return XkbKeycodeToKeysym(display, xkc, 0, 0);
}

//! Explict convertion for non-text symbols
typedef std::unordered_map<KeySym, KeyCode> XtoOIS_KeyMap;
XtoOIS_KeyMap keyConversion;

OIS::KeyCode convert(KeySym ksym);
XtoOIS_KeyMap keyConversionToOIS;

typedef std::unordered_map<KeyCode, KeySym> OIStoX_KeyMap;
OIStoX_KeyMap keyConversionFromOIS;

void addKeyConversion(KeySym x_key, KeyCode ois_key);

//! Depressed Key List
char KeyBuffer[256];
Expand Down
100 changes: 47 additions & 53 deletions src/linux/LinuxKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,47 +47,53 @@ LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab) :

static_cast<LinuxInputManager*>(mCreator)->_setKeyboardUsed(true);

keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Up, KC_UP));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Down, KC_DOWN));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Left, KC_LEFT));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Right, KC_RIGHT));

keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Divide, KC_DIVIDE));

keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Home, KC_NUMPAD7));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Up, KC_NUMPAD8));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Page_Up, KC_NUMPAD9));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Left, KC_NUMPAD4));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Begin, KC_NUMPAD5));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Right, KC_NUMPAD6));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_End, KC_NUMPAD1));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Down, KC_NUMPAD2));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Page_Down, KC_NUMPAD3));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Insert, KC_NUMPAD0));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Delete, KC_DECIMAL));

keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Page_Up, KC_PGUP));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Page_Down, KC_PGDOWN));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Home, KC_HOME));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_End, KC_END));

keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Print, KC_SYSRQ));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Scroll_Lock, KC_SCROLL));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Pause, KC_PAUSE));

keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Shift_R, KC_RSHIFT));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Shift_L, KC_LSHIFT));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Alt_R, KC_RMENU));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Alt_L, KC_LMENU));

keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Insert, KC_INSERT));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Delete, KC_DELETE));

keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Super_L, KC_LWIN));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Super_R, KC_RWIN));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Menu, KC_APPS));

addKeyConversion(XK_Up, KC_UP);
addKeyConversion(XK_Down, KC_DOWN);
addKeyConversion(XK_Left, KC_LEFT);
addKeyConversion(XK_Right, KC_RIGHT);

addKeyConversion(XK_KP_Divide, KC_DIVIDE);

addKeyConversion(XK_KP_Home, KC_NUMPAD7);
addKeyConversion(XK_KP_Up, KC_NUMPAD8);
addKeyConversion(XK_KP_Page_Up, KC_NUMPAD9);
addKeyConversion(XK_KP_Left, KC_NUMPAD4);
addKeyConversion(XK_KP_Begin, KC_NUMPAD5);
addKeyConversion(XK_KP_Right, KC_NUMPAD6);
addKeyConversion(XK_KP_End, KC_NUMPAD1);
addKeyConversion(XK_KP_Down, KC_NUMPAD2);
addKeyConversion(XK_KP_Page_Down, KC_NUMPAD3);
addKeyConversion(XK_KP_Insert, KC_NUMPAD0);
addKeyConversion(XK_KP_Delete, KC_DECIMAL);

addKeyConversion(XK_Page_Up, KC_PGUP);
addKeyConversion(XK_Page_Down, KC_PGDOWN);
addKeyConversion(XK_Home, KC_HOME);
addKeyConversion(XK_End, KC_END);

addKeyConversion(XK_Print, KC_SYSRQ);
addKeyConversion(XK_Scroll_Lock, KC_SCROLL);
addKeyConversion(XK_Pause, KC_PAUSE);

addKeyConversion(XK_Shift_R, KC_RSHIFT);
addKeyConversion(XK_Shift_L, KC_LSHIFT);
addKeyConversion(XK_Alt_R, KC_RMENU);
addKeyConversion(XK_Alt_L, KC_LMENU);

addKeyConversion(XK_Insert, KC_INSERT);
addKeyConversion(XK_Delete, KC_DELETE);

addKeyConversion(XK_Super_L, KC_LWIN);
addKeyConversion(XK_Super_R, KC_RWIN);
addKeyConversion(XK_Menu, KC_APPS);
}

void LinuxKeyboard::addKeyConversion(KeySym x_key, KeyCode ois_key)
{
keyConversionToOIS.insert(XtoOIS_KeyMap::value_type(x_key, ois_key));
keyConversionFromOIS.insert(OIStoX_KeyMap::value_type(ois_key, x_key));
}
//-------------------------------------------------------------------//
void LinuxKeyboard::_initialize()
{
Expand Down Expand Up @@ -365,13 +371,6 @@ void LinuxKeyboard::setBuffered(bool buffered)
mBuffered = buffered;
}

OIS::KeyCode LinuxKeyboard::convert(KeySym kc)
{
const auto result = keyConversion.find(kc);
if(result == keyConversion.end())
return KC_UNASSIGNED; //No explicit conversion for the symbol;
return result->second;
}
//-------------------------------------------------------------------//
bool LinuxKeyboard::_injectKeyDown(KeyCode kc, int text)
{
Expand Down Expand Up @@ -431,13 +430,8 @@ const std::string& LinuxKeyboard::getAsString(KeyCode kc)
//-------------------------------------------------------------------//
OIS::KeyCode LinuxKeyboard::getAsKeyCode(std::string str)
{
OIS::KeyCode mGetKeyCode;
/*
* TODO fixme!
KeySym X11Key = XStringToKeysym(str.c_str());
mGetKeyCode = keyConversion.at(X11Key);
*/
return mGetKeyCode;
KeySym X11Key = XStringToKeysym(str.c_str());
return KeySymToOISKeyCode(X11Key);
}

//-------------------------------------------------------------------//
Expand Down

0 comments on commit 27c44b0

Please sign in to comment.