]> git.tdb.fi Git - libs/gui.git/blob - source/input/windows/keyboard.cpp
Add KEY_NONE constant
[libs/gui.git] / source / input / windows / keyboard.cpp
1 #include <windows.h>
2 #include <msp/graphics/window_private.h>
3 #include "keyboard.h"
4 #include "keys.h"
5 #include "keys_private.h"
6
7 #define MAPVK_VK_TO_VSC 0
8
9 namespace Msp {
10 namespace Input {
11
12 std::string Keyboard::get_button_name(unsigned btn) const
13 {
14         if(btn==KEY_NONE)
15                 return "None";
16
17         char buf[128];
18         unsigned scan = MapVirtualKey(key_to_sys(btn), MAPVK_VK_TO_VSC);
19         if(!GetKeyNameText(scan<<16, buf, sizeof(buf)))
20                 return Device::get_button_name(btn);
21         return buf;
22 }
23
24 void Keyboard::input_event(const Graphics::Window::Event &event)
25 {
26         switch(event.msg)
27         {
28         case WM_KEYDOWN:
29         case WM_KEYUP:
30                 set_button_state(key_from_sys(event.wparam), event.msg==WM_KEYDOWN, true);
31                 break;
32         case WM_CHAR:
33                 signal_character.emit(event.wparam);
34                 break;
35         }
36 }
37
38 } // namespace Input
39 } // namespace Msp