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