|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: Fl_get_key_win32.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $" 00003 // 00004 // WIN32 keyboard state routines for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00028 // Return the current state of a key. Keys are named by fltk symbols, 00029 // which are actually X keysyms. So this has to translate to MSWindows 00030 // VK_x symbols. 00031 00032 #include <FL/Fl.H> 00033 #include <FL/x.H> 00034 00035 // convert an Fltk (X) keysym to a MSWindows VK symbol: 00036 // See also the inverse converter in Fl_win32.cxx 00037 // This table is in numeric order by Fltk symbol order for binary search: 00038 00039 static const struct {unsigned short vk, fltk;} vktab[] = { 00040 {VK_SPACE, ' '}, 00041 {'1', '!'}, 00042 {0xde, '\"'}, 00043 {'3', '#'}, 00044 {'4', '$'}, 00045 {'5', '%'}, 00046 {'7', '&'}, 00047 {0xde, '\''}, 00048 {'9', '('}, 00049 {'0', ')'}, 00050 {'8', '*'}, 00051 {0xbb, '+'}, 00052 {0xbc, ','}, 00053 {0xbd, '-'}, 00054 {0xbe, '.'}, 00055 {0xbf, '/'}, 00056 {0xba, ':'}, 00057 {0xba, ';'}, 00058 {0xbc, '<'}, 00059 {0xbb, '='}, 00060 {0xbe, '>'}, 00061 {0xbf, '?'}, 00062 {'2', '@'}, 00063 {0xdb, '['}, 00064 {0xdc, '\\'}, 00065 {0xdd, ']'}, 00066 {'6', '^'}, 00067 {0xbd, '_'}, 00068 {0xc0, '`'}, 00069 {0xdb, '{'}, 00070 {0xdc, '|'}, 00071 {0xdd, '}'}, 00072 {0xc0, '~'}, 00073 {VK_BACK, FL_BackSpace}, 00074 {VK_TAB, FL_Tab}, 00075 {VK_CLEAR, 0xff0b/*XK_Clear*/}, 00076 {VK_RETURN, FL_Enter}, 00077 {VK_PAUSE, FL_Pause}, 00078 {VK_SCROLL, FL_Scroll_Lock}, 00079 {VK_ESCAPE, FL_Escape}, 00080 {VK_HOME, FL_Home}, 00081 {VK_LEFT, FL_Left}, 00082 {VK_UP, FL_Up}, 00083 {VK_RIGHT, FL_Right}, 00084 {VK_DOWN, FL_Down}, 00085 {VK_PRIOR, FL_Page_Up}, 00086 {VK_NEXT, FL_Page_Down}, 00087 {VK_END, FL_End}, 00088 {VK_SNAPSHOT, FL_Print}, 00089 {VK_INSERT, FL_Insert}, 00090 {VK_APPS, FL_Menu}, 00091 {VK_NUMLOCK, FL_Num_Lock}, 00092 //{VK_???, FL_KP_Enter}, 00093 {VK_MULTIPLY, FL_KP+'*'}, 00094 {VK_ADD, FL_KP+'+'}, 00095 {VK_SUBTRACT, FL_KP+'-'}, 00096 {VK_DECIMAL, FL_KP+'.'}, 00097 {VK_DIVIDE, FL_KP+'/'}, 00098 {VK_LSHIFT, FL_Shift_L}, 00099 {VK_RSHIFT, FL_Shift_R}, 00100 {VK_LCONTROL, FL_Control_L}, 00101 {VK_RCONTROL, FL_Control_R}, 00102 {VK_CAPITAL, FL_Caps_Lock}, 00103 {VK_LWIN, FL_Meta_L}, 00104 {VK_RWIN, FL_Meta_R}, 00105 {VK_LMENU, FL_Alt_L}, 00106 {VK_RMENU, FL_Alt_R}, 00107 {VK_DELETE, FL_Delete} 00108 }; 00109 00110 static int fltk2ms(int fltk) { 00111 if (fltk >= '0' && fltk <= '9') return fltk; 00112 if (fltk >= 'A' && fltk <= 'Z') return fltk; 00113 if (fltk >= 'a' && fltk <= 'z') return fltk-('a'-'A'); 00114 if (fltk > FL_F && fltk <= FL_F+16) return fltk-(FL_F-(VK_F1-1)); 00115 if (fltk >= FL_KP+'0' && fltk<=FL_KP+'9') return fltk-(FL_KP+'0'-VK_NUMPAD0); 00116 int a = 0; 00117 int b = sizeof(vktab)/sizeof(*vktab); 00118 while (a < b) { 00119 int c = (a+b)/2; 00120 if (vktab[c].fltk == fltk) return vktab[c].vk; 00121 if (vktab[c].fltk < fltk) a = c+1; else b = c; 00122 } 00123 return 0; 00124 } 00125 00126 int Fl::event_key(int k) { 00127 return GetKeyState(fltk2ms(k))&~1; 00128 } 00129 00130 int Fl::get_key(int k) { 00131 uchar foo[256]; 00132 GetKeyboardState(foo); 00133 return foo[fltk2ms(k)]&~1; 00134 } 00135 00136 // 00137 // End of "$Id: Fl_get_key_win32.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $". 00138 //