X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fkeyboard.cpp;h=2e3c92df97fdb88ec2d974d4cd3a912502ab417e;hb=77d8b98374ab07be0d14c9c88502c6a803041040;hp=ab01e6261eff14eb7345de57c34e1cd0412607bd;hpb=61eeb96535d1575ca0cf698d833c0ddfc7ae0f50;p=libs%2Fgui.git diff --git a/source/keyboard.cpp b/source/keyboard.cpp index ab01e62..2e3c92d 100644 --- a/source/keyboard.cpp +++ b/source/keyboard.cpp @@ -5,19 +5,37 @@ Copyright © 2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include +#include "display.h" #include "keyboard.h" namespace Msp { namespace Input { -Keyboard::Keyboard(Graphics::Window &window) +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);