]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/windows/keyboard.cpp
Split platform-specific parts into separate directories
[libs/gui.git] / source / input / windows / keyboard.cpp
diff --git a/source/input/windows/keyboard.cpp b/source/input/windows/keyboard.cpp
new file mode 100644 (file)
index 0000000..24b019e
--- /dev/null
@@ -0,0 +1,38 @@
+#include <windows.h>
+#include <msp/graphics/window_private.h>
+#include "keyboard.h"
+#include "keys_private.h"
+
+#define MAPVK_VK_TO_VSC 0
+
+namespace Msp {
+namespace Input {
+
+std::string Keyboard::get_button_name(unsigned btn) const
+{
+       if(btn==0)
+               return "None";
+
+       char buf[128];
+       unsigned scan = MapVirtualKey(key_to_sys(btn), MAPVK_VK_TO_VSC);
+       if(!GetKeyNameText(scan<<16, buf, sizeof(buf)))
+               return Device::get_button_name(btn);
+       return buf;
+}
+
+void Keyboard::input_event(const Graphics::Window::Event &event)
+{
+       switch(event.msg)
+       {
+       case WM_KEYDOWN:
+       case WM_KEYUP:
+               set_button_state(key_from_sys(event.wparam), event.msg==WM_KEYDOWN, true);
+               break;
+       case WM_CHAR:
+               signal_character.emit(event.wparam);
+               break;
+       }
+}
+
+} // namespace Input
+} // namespace Msp