]> git.tdb.fi Git - libs/gui.git/blob - source/input/keyboard.cpp
Reorganize files to separate gbase and input
[libs/gui.git] / source / input / keyboard.cpp
1 /* $Id$
2
3 This file is part of libmspgbase
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <msp/strings/formatter.h>
9 #include "../gbase/display.h"
10 #include "keyboard.h"
11
12 namespace Msp {
13 namespace Input {
14
15 Keyboard::Keyboard(Graphics::Window &w):
16         window(w)
17 {
18         name="Keyboard";
19
20         buttons.resize(256, false);
21
22         window.signal_key_press.connect(sigc::mem_fun(this, &Keyboard::key_press));
23         window.signal_key_release.connect(sigc::mem_fun(this, &Keyboard::key_release));
24 }
25
26 std::string Keyboard::get_button_name(unsigned btn) const
27 {
28 #ifndef WIN32
29         KeySym ksym=XKeycodeToKeysym(window.get_display().get_display(), btn, 0);
30         return XKeysymToString(ksym);
31 #else
32         char buf[128];
33         if(!GetKeyNameText(btn<<16, buf, sizeof(buf)))
34                 return format("Key %d", btn);
35         return buf;
36 #endif
37 }
38
39 void Keyboard::key_press(unsigned key, unsigned, unsigned)
40 {
41         set_button_state(key, true, true);
42 }
43
44 void Keyboard::key_release(unsigned key, unsigned)
45 {
46         set_button_state(key, false, true);
47 }
48
49 } // namespace Input
50 } // namespace Msp