]> git.tdb.fi Git - libs/gui.git/blob - source/input/keys.cpp
Split platform-specific parts into separate directories
[libs/gui.git] / source / input / keys.cpp
1 #include <map>
2 #include <stdexcept>
3 #include "keys.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace Input {
9
10 extern unsigned sys_keymap[];
11
12 unsigned key_from_sys(unsigned code)
13 {
14         static bool init_done = false;
15         static map<unsigned, unsigned> reverse_map;
16
17         if(!init_done)
18         {
19                 for(unsigned i=0; i<N_KEYS_; ++i)
20                         if(sys_keymap[i])
21                                 reverse_map[sys_keymap[i]] = i;
22
23                 init_done = true;
24         }
25
26         map<unsigned, unsigned>::const_iterator i = reverse_map.find(code);
27         if(i!=reverse_map.end())
28                 return i->second;
29
30         return 0;
31 }
32
33 unsigned key_to_sys(unsigned key)
34 {
35         if(key>=N_KEYS_)
36                 throw invalid_argument("key_to_sys");
37         return sys_keymap[key];
38 }
39
40 } // namespace Input
41 } // namespace Msp