X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fkeyboard.cpp;h=4372be4f42bd5fbcfc707a842eae1494511c9665;hb=7a4a508629d370c4a79791c7e62fd6f59e8564e9;hp=240d700fccc4b45620cbd40c4f728face25f7c58;hpb=b453da0696b24cc02a7fcf5127afcd7baef9c801;p=libs%2Fgui.git diff --git a/source/input/keyboard.cpp b/source/input/keyboard.cpp index 240d700..4372be4 100644 --- a/source/input/keyboard.cpp +++ b/source/input/keyboard.cpp @@ -8,6 +8,7 @@ Distributed under the LGPL #include #include "../gbase/display.h" #include "keyboard.h" +#include "keys.h" namespace Msp { namespace Input { @@ -17,7 +18,7 @@ Keyboard::Keyboard(Graphics::Window &w): { name="Keyboard"; - buttons.resize(256, false); + buttons.resize(N_KEYS_, false); window.signal_key_press.connect(sigc::mem_fun(this, &Keyboard::key_press)); window.signal_key_release.connect(sigc::mem_fun(this, &Keyboard::key_release)); @@ -25,12 +26,17 @@ Keyboard::Keyboard(Graphics::Window &w): std::string Keyboard::get_button_name(unsigned btn) const { + if(btn==0) + return "None"; #ifndef WIN32 - KeySym ksym=XKeycodeToKeysym(window.get_display().get_display(), btn, 0); - return XKeysymToString(ksym); + const char *str=XKeysymToString(key_to_sys(btn)); + if(!str) + return format("Key %d", btn); + return str; #else char buf[128]; - if(!GetKeyNameText(btn<<16, buf, sizeof(buf))) + unsigned scan=MapVirtualKey(key_to_sys(btn), MAPVK_VK_TO_VCS); + if(!GetKeyNameText(scan<<16, buf, sizeof(buf))) return format("Key %d", btn); return buf; #endif @@ -38,12 +44,12 @@ std::string Keyboard::get_button_name(unsigned btn) const void Keyboard::key_press(unsigned key, unsigned, unsigned) { - set_button_state(key, true, true); + set_button_state(key_from_sys(key), true, true); } void Keyboard::key_release(unsigned key, unsigned) { - set_button_state(key, false, true); + set_button_state(key_from_sys(key), false, true); } } // namespace Input