Tweak themes for more color consistency.
[ntk.git] / src / Fl_get_key_win32.cxx
blobe935a2ebf8f7468775ac10f45e0a2b9855ac69d8
1 //
2 // "$Id: Fl_get_key_win32.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $"
3 //
4 // WIN32 keyboard state routines for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // Return the current state of a key. Keys are named by fltk symbols,
29 // which are actually X keysyms. So this has to translate to MSWindows
30 // VK_x symbols.
32 #include <FL/Fl.H>
33 #include <FL/x.H>
35 // convert an Fltk (X) keysym to a MSWindows VK symbol:
36 // See also the inverse converter in Fl_win32.cxx
37 // This table is in numeric order by Fltk symbol order for binary search:
39 static const struct {unsigned short vk, fltk;} vktab[] = {
40 {VK_SPACE, ' '},
41 {'1', '!'},
42 {0xde, '\"'},
43 {'3', '#'},
44 {'4', '$'},
45 {'5', '%'},
46 {'7', '&'},
47 {0xde, '\''},
48 {'9', '('},
49 {'0', ')'},
50 {'8', '*'},
51 {0xbb, '+'},
52 {0xbc, ','},
53 {0xbd, '-'},
54 {0xbe, '.'},
55 {0xbf, '/'},
56 {0xba, ':'},
57 {0xba, ';'},
58 {0xbc, '<'},
59 {0xbb, '='},
60 {0xbe, '>'},
61 {0xbf, '?'},
62 {'2', '@'},
63 {0xdb, '['},
64 {0xdc, '\\'},
65 {0xdd, ']'},
66 {'6', '^'},
67 {0xbd, '_'},
68 {0xc0, '`'},
69 {0xdb, '{'},
70 {0xdc, '|'},
71 {0xdd, '}'},
72 {0xc0, '~'},
73 {VK_BACK, FL_BackSpace},
74 {VK_TAB, FL_Tab},
75 {VK_CLEAR, 0xff0b/*XK_Clear*/},
76 {VK_RETURN, FL_Enter},
77 {VK_PAUSE, FL_Pause},
78 {VK_SCROLL, FL_Scroll_Lock},
79 {VK_ESCAPE, FL_Escape},
80 {VK_HOME, FL_Home},
81 {VK_LEFT, FL_Left},
82 {VK_UP, FL_Up},
83 {VK_RIGHT, FL_Right},
84 {VK_DOWN, FL_Down},
85 {VK_PRIOR, FL_Page_Up},
86 {VK_NEXT, FL_Page_Down},
87 {VK_END, FL_End},
88 {VK_SNAPSHOT, FL_Print},
89 {VK_INSERT, FL_Insert},
90 {VK_APPS, FL_Menu},
91 {VK_NUMLOCK, FL_Num_Lock},
92 //{VK_???, FL_KP_Enter},
93 {VK_MULTIPLY, FL_KP+'*'},
94 {VK_ADD, FL_KP+'+'},
95 {VK_SUBTRACT, FL_KP+'-'},
96 {VK_DECIMAL, FL_KP+'.'},
97 {VK_DIVIDE, FL_KP+'/'},
98 {VK_LSHIFT, FL_Shift_L},
99 {VK_RSHIFT, FL_Shift_R},
100 {VK_LCONTROL, FL_Control_L},
101 {VK_RCONTROL, FL_Control_R},
102 {VK_CAPITAL, FL_Caps_Lock},
103 {VK_LWIN, FL_Meta_L},
104 {VK_RWIN, FL_Meta_R},
105 {VK_LMENU, FL_Alt_L},
106 {VK_RMENU, FL_Alt_R},
107 {VK_DELETE, FL_Delete}
110 static int fltk2ms(int fltk) {
111 if (fltk >= '0' && fltk <= '9') return fltk;
112 if (fltk >= 'A' && fltk <= 'Z') return fltk;
113 if (fltk >= 'a' && fltk <= 'z') return fltk-('a'-'A');
114 if (fltk > FL_F && fltk <= FL_F+16) return fltk-(FL_F-(VK_F1-1));
115 if (fltk >= FL_KP+'0' && fltk<=FL_KP+'9') return fltk-(FL_KP+'0'-VK_NUMPAD0);
116 int a = 0;
117 int b = sizeof(vktab)/sizeof(*vktab);
118 while (a < b) {
119 int c = (a+b)/2;
120 if (vktab[c].fltk == fltk) return vktab[c].vk;
121 if (vktab[c].fltk < fltk) a = c+1; else b = c;
123 return 0;
126 int Fl::event_key(int k) {
127 return GetKeyState(fltk2ms(k))&~1;
130 int Fl::get_key(int k) {
131 uchar foo[256];
132 GetKeyboardState(foo);
133 return foo[fltk2ms(k)]&~1;
137 // End of "$Id: Fl_get_key_win32.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $".