3 This file is part of libmspgbase
4 Copyright © 2007-2008, 2010 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
13 #include <msp/strings/formatter.h>
14 #include "../gbase/display.h"
18 #define MAPVK_VK_TO_VSC 0
23 Keyboard::Keyboard(Graphics::EventSource &s):
28 buttons.resize(N_KEYS_, false);
30 source.signal_key_press.connect(sigc::mem_fun(this, &Keyboard::key_press));
31 source.signal_key_release.connect(sigc::mem_fun(this, &Keyboard::key_release));
34 std::string Keyboard::get_button_name(unsigned btn) const
39 const char *str=XKeysymToString(key_to_sys(btn));
41 return format("Key %d", btn);
45 unsigned scan=MapVirtualKey(key_to_sys(btn), MAPVK_VK_TO_VSC);
46 if(!GetKeyNameText(scan<<16, buf, sizeof(buf)))
47 return format("Key %d", btn);
52 void Keyboard::key_press(unsigned key, unsigned, unsigned)
54 set_button_state(key_from_sys(key), true, true);
57 void Keyboard::key_release(unsigned key, unsigned)
59 set_button_state(key_from_sys(key), false, true);