2 // "$Id: Fl_get_key_win32.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $"
4 // WIN32 keyboard state routines for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
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
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
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
[] = {
73 {VK_BACK
, FL_BackSpace
},
75 {VK_CLEAR
, 0xff0b/*XK_Clear*/},
76 {VK_RETURN
, FL_Enter
},
78 {VK_SCROLL
, FL_Scroll_Lock
},
79 {VK_ESCAPE
, FL_Escape
},
85 {VK_PRIOR
, FL_Page_Up
},
86 {VK_NEXT
, FL_Page_Down
},
88 {VK_SNAPSHOT
, FL_Print
},
89 {VK_INSERT
, FL_Insert
},
91 {VK_NUMLOCK
, FL_Num_Lock
},
92 //{VK_???, FL_KP_Enter},
93 {VK_MULTIPLY
, 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
);
117 int b
= sizeof(vktab
)/sizeof(*vktab
);
120 if (vktab
[c
].fltk
== fltk
) return vktab
[c
].vk
;
121 if (vktab
[c
].fltk
< fltk
) a
= c
+1; else b
= c
;
126 int Fl::event_key(int k
) {
127 return GetKeyState(fltk2ms(k
))&~1;
130 int Fl::get_key(int k
) {
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 $".