]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/keyboard.cpp
Fall back to Device::get_*_name if name can't be determined
[libs/gui.git] / source / input / keyboard.cpp
index ea66cf28ab11aa9d74f55680293336f4e5efae83..0f4d4ab848c772efb084f14cd18953c6cb412e26 100644 (file)
@@ -8,7 +8,6 @@
 #include <msp/graphics/window.h>
 #include <msp/graphics/display_priv.h>
 #include <msp/graphics/window_priv.h>
-#include <msp/strings/format.h>
 #include "keyboard.h"
 #include "keys.h"
 
@@ -34,13 +33,13 @@ std::string Keyboard::get_button_name(unsigned btn) const
 #ifndef WIN32
        const char *str = XKeysymToString(key_to_sys(btn));
        if(!str)
-               return format("Key %d", btn);
+               return Device::get_button_name(btn);
        return str;
 #else
        char buf[128];
        unsigned scan = MapVirtualKey(key_to_sys(btn), MAPVK_VK_TO_VSC);
        if(!GetKeyNameText(scan<<16, buf, sizeof(buf)))
-               return format("Key %d", btn);
+               return Device::get_button_name(btn);
        return buf;
 #endif
 }
@@ -66,7 +65,8 @@ void Keyboard::input_event(const Graphics::Window::Event &event)
                {
                        KeySym keysym = XKeycodeToKeysym(window.get_display().get_private().display, event.xevent.xkey.keycode, 0);
                        if(keysym!=NoSymbol)
-                               set_button_state(key_from_sys(keysym), event.xevent.type==KeyPress, true);
+                               if(unsigned key = key_from_sys(keysym))
+                                       set_button_state(key, event.xevent.type==KeyPress, true);
                        if(event.xevent.type==KeyPress)
                        {
                                char ch;