Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 156 lines (131 sloc) 3.747 kb
a9461cd initializing repo from version 0.10.2 minus the example files
Julian authored
1 // key.cpp
2 // Revision 9-jan-2005
3
4 #include "key.h"
5 #include "trace.h"
6 #include "blassic.h"
7
8 #include <map>
9
10 #include <iostream> // For debug info only.
11
12 //#ifdef _Windows
13 #ifdef BLASSIC_USE_WINDOWS
14
15 #include <windows.h>
16
17 #elif defined BLASSIC_USE_X
18
19 #include <X11/keysym.h>
20
21 #endif
22
23 const std::string
24 strPAGEUP ("PAGEUP"),
25 strPAGEDOWN ("PAGEDOWN"),
26 strEND ("END"),
27 strHOME ("HOME"),
28 strLEFT ("LEFT"),
29 strUP ("UP"),
30 strRIGHT ("RIGHT"),
31 strDOWN ("DOWN"),
32 strINSERT ("INSERT"),
33 strDELETE ("DELETE"),
34 strF1 ("F1"),
35 strF2 ("F2"),
36 strF3 ("F3"),
37 strF4 ("F4"),
38 strF5 ("F5"),
39 strF6 ("F6"),
40 strF7 ("F7"),
41 strF8 ("F8"),
42 strF9 ("F9"),
43 strF10 ("F10"),
44 strF11 ("F11"),
45 strF12 ("F12"),
46 strENTER ("\n"),
47 strCLICK ("CLICK"),
48 strSCLICK ("SCLICK"),
49 strRELEASE ("RELEASE"),
50 strSRELEASE ("SRELEASE");
51
52 namespace {
53
54 typedef std::map <unsigned int, std::string> mapkey_t;
55
56 mapkey_t mapkey;
57
58 inline void assignmapkey (unsigned int code, const std::string & name)
59 {
60 #ifndef NDEBUG
61 mapkey_t::iterator it;
62 if ( (it= mapkey.find (code) ) != mapkey.end () )
63 {
64 std::cerr << "Error: key " << name <<
65 " has equal code than " << it->second <<
66 std::endl;
67 throw 1;
68 }
69 #endif
70 mapkey [code]= name;
71 }
72
73 bool initmapkey ()
74 {
75 TRACEFUNC (tr, "initmapkey");
76
77 //#ifdef _Windows
78 #ifdef BLASSIC_USE_WINDOWS
79
80 assignmapkey (VK_PRIOR, strPAGEUP);
81 assignmapkey (VK_NEXT, strPAGEDOWN);
82 assignmapkey (VK_END, strEND);
83 assignmapkey (VK_HOME, strHOME);
84 assignmapkey (VK_LEFT, strLEFT);
85 assignmapkey (VK_UP, strUP);
86 assignmapkey (VK_RIGHT, strRIGHT);
87 assignmapkey (VK_DOWN, strDOWN);
88 assignmapkey (VK_INSERT, strINSERT);
89 assignmapkey (VK_DELETE, strDELETE);
90 assignmapkey (VK_F1, strF1);
91 assignmapkey (VK_F2, strF2);
92 assignmapkey (VK_F3, strF3);
93 assignmapkey (VK_F4, strF4);
94 assignmapkey (VK_F5, strF5);
95 assignmapkey (VK_F6, strF6);
96 assignmapkey (VK_F7, strF7);
97 assignmapkey (VK_F8, strF8);
98 assignmapkey (VK_F9, strF9);
99 assignmapkey (VK_F10, strF10);
100 assignmapkey (VK_F11, strF11);
101 assignmapkey (VK_F12, strF12);
102
103 #elif defined BLASSIC_USE_X
104
105 assignmapkey (XK_Prior, strPAGEUP);
106 assignmapkey (XK_KP_Prior, strPAGEUP);
107 assignmapkey (XK_Next, strPAGEDOWN);
108 assignmapkey (XK_KP_Next, strPAGEDOWN);
109 assignmapkey (XK_End, strEND);
110 assignmapkey (XK_KP_End, strEND);
111 assignmapkey (XK_Home, strHOME);
112 assignmapkey (XK_KP_Home, strHOME);
113 assignmapkey (XK_Left, strLEFT);
114 assignmapkey (XK_KP_Left, strLEFT);
115 assignmapkey (XK_Up, strUP);
116 assignmapkey (XK_KP_Up, strUP);
117 assignmapkey (XK_Right, strRIGHT);
118 assignmapkey (XK_KP_Right, strRIGHT);
119 assignmapkey (XK_Down, strDOWN);
120 assignmapkey (XK_KP_Down, strDOWN);
121 assignmapkey (XK_Insert, strINSERT);
122 assignmapkey (XK_KP_Insert, strINSERT);
123 assignmapkey (XK_Delete, strDELETE);
124 assignmapkey (XK_KP_Delete, strDELETE);
125 assignmapkey (XK_F1, strF1);
126 assignmapkey (XK_F2, strF2);
127 assignmapkey (XK_F3, strF3);
128 assignmapkey (XK_F4, strF4);
129 assignmapkey (XK_F5, strF5);
130 assignmapkey (XK_F6, strF6);
131 assignmapkey (XK_F7, strF7);
132 assignmapkey (XK_F8, strF8);
133 assignmapkey (XK_F9, strF9);
134 assignmapkey (XK_F10, strF10);
135 assignmapkey (XK_F11, strF11);
136 assignmapkey (XK_F12, strF12);
137
138 #endif
139
140 return true;
141 }
142
143 const bool mapkeyinited= initmapkey ();
144
145 } // namespace
146
147 std::string string_from_key (unsigned int key)
148 {
149 mapkey_t::const_iterator it= mapkey.find (key);
150 if (it != mapkey.end () )
151 return it->second;
152 return std::string ();
153 }
154
155 // End of key.cpp
Something went wrong with that request. Please try again.