7 #include <msp/graphics/display.h>
8 #include <msp/graphics/window.h>
9 #include <msp/graphics/display_priv.h>
10 #include <msp/graphics/window_priv.h>
11 #include <msp/strings/format.h>
15 #define MAPVK_VK_TO_VSC 0
20 Keyboard::Keyboard(Graphics::Window &w):
25 buttons.resize(N_KEYS_, false);
27 window.signal_input_event.connect(sigc::mem_fun(this, &Keyboard::input_event));
30 std::string Keyboard::get_button_name(unsigned btn) const
35 const char *str = XKeysymToString(key_to_sys(btn));
37 return format("Key %d", btn);
41 unsigned scan = MapVirtualKey(key_to_sys(btn), MAPVK_VK_TO_VSC);
42 if(!GetKeyNameText(scan<<16, buf, sizeof(buf)))
43 return format("Key %d", btn);
48 void Keyboard::input_event(const Graphics::Window::Event &event)
55 set_button_state(key_from_sys(event.wparam), event.msg==WM_KEYDOWN, true);
58 signal_character.emit(event.wparam);
62 switch(event.xevent.type)
67 KeySym keysym = XKeycodeToKeysym(window.get_display().get_private().display, event.xevent.xkey.keycode, 0);
69 if(unsigned key = key_from_sys(keysym))
70 set_button_state(key, event.xevent.type==KeyPress, true);
71 if(event.xevent.type==KeyPress)
74 if(XLookupString(const_cast<XKeyEvent *>(&event.xevent.xkey), &ch, 1, 0, 0))
75 // XLookupString always returns Latin-1
76 signal_character.emit(static_cast<unsigned char>(ch));