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>
14 #define MAPVK_VK_TO_VSC 0
19 Keyboard::Keyboard(Graphics::Window &w):
24 buttons.resize(N_KEYS_, false);
26 window.signal_input_event.connect(sigc::mem_fun(this, &Keyboard::input_event));
29 std::string Keyboard::get_button_name(unsigned btn) const
34 const char *str = XKeysymToString(key_to_sys(btn));
36 return Device::get_button_name(btn);
40 unsigned scan = MapVirtualKey(key_to_sys(btn), MAPVK_VK_TO_VSC);
41 if(!GetKeyNameText(scan<<16, buf, sizeof(buf)))
42 return Device::get_button_name(btn);
47 void Keyboard::input_event(const Graphics::Window::Event &event)
54 set_button_state(key_from_sys(event.wparam), event.msg==WM_KEYDOWN, true);
57 signal_character.emit(event.wparam);
61 switch(event.xevent.type)
66 KeySym keysym = XLookupKeysym(const_cast<XKeyEvent *>(&event.xevent.xkey), 0);
68 if(unsigned key = key_from_sys(keysym))
69 set_button_state(key, event.xevent.type==KeyPress, true);
70 if(event.xevent.type==KeyPress)
73 if(XLookupString(const_cast<XKeyEvent *>(&event.xevent.xkey), &ch, 1, 0, 0))
74 // XLookupString always returns Latin-1
75 signal_character.emit(static_cast<unsigned char>(ch));