]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/keyboard.cpp
Reorganize files to separate gbase and input
[libs/gui.git] / source / input / keyboard.cpp
diff --git a/source/input/keyboard.cpp b/source/input/keyboard.cpp
new file mode 100644 (file)
index 0000000..240d700
--- /dev/null
@@ -0,0 +1,50 @@
+/* $Id$
+
+This file is part of libmspgbase
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include <msp/strings/formatter.h>
+#include "../gbase/display.h"
+#include "keyboard.h"
+
+namespace Msp {
+namespace Input {
+
+Keyboard::Keyboard(Graphics::Window &w):
+       window(w)
+{
+       name="Keyboard";
+
+       buttons.resize(256, false);
+
+       window.signal_key_press.connect(sigc::mem_fun(this, &Keyboard::key_press));
+       window.signal_key_release.connect(sigc::mem_fun(this, &Keyboard::key_release));
+}
+
+std::string Keyboard::get_button_name(unsigned btn) const
+{
+#ifndef WIN32
+       KeySym ksym=XKeycodeToKeysym(window.get_display().get_display(), btn, 0);
+       return XKeysymToString(ksym);
+#else
+       char buf[128];
+       if(!GetKeyNameText(btn<<16, buf, sizeof(buf)))
+               return format("Key %d", btn);
+       return buf;
+#endif
+}
+
+void Keyboard::key_press(unsigned key, unsigned, unsigned)
+{
+       set_button_state(key, true, true);
+}
+
+void Keyboard::key_release(unsigned key, unsigned)
+{
+       set_button_state(key, false, true);
+}
+
+} // namespace Input
+} // namespace Msp