home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / Fl_get_key_win32.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-16  |  3.6 KB  |  137 lines

  1. //
  2. // "$Id: Fl_get_key_win32.cxx,v 1.4.2.2 1999/09/16 05:34:26 bill Exp $"
  3. //
  4. // WIN32 keyboard state routines for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 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.
  12. //
  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.
  17. //
  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.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Return the current state of a key.  Keys are named by fltk symbols,
  27. // which are actually X keysyms.  So this has to translate to MSWindows
  28. // VK_x symbols.
  29.  
  30. #include <FL/Fl.H>
  31. #include <FL/win32.H>
  32.  
  33. // convert an Fltk (X) keysym to a MSWindows VK symbol:
  34. // See also the inverse converter in Fl_win32.C
  35. // This table is in numeric order by Fltk symbol order for binary search:
  36.  
  37. static const struct {unsigned short vk, fltk;} vktab[] = {
  38.   {VK_SPACE,    ' '},
  39.   {'1',        '!'},
  40.   {0xde,    '\"'},
  41.   {'3',        '#'},
  42.   {'4',        '$'},
  43.   {'5',        '%'},
  44.   {'7',        '&'},
  45.   {0xde,    '\''},
  46.   {'9',        '('},
  47.   {'0',        ')'},
  48.   {'8',        '*'},
  49.   {0xbb,    '+'},
  50.   {0xbc,    ','},
  51.   {0xbd,    '-'},
  52.   {0xbe,    '.'},
  53.   {0xbf,    '/'},
  54.   {0xba,    ':'},
  55.   {0xba,    ';'},
  56.   {0xbc,    '<'},
  57.   {0xbb,    '='},
  58.   {0xbe,    '>'},
  59.   {0xbf,    '?'},
  60.   {'2',        '@'},
  61.   {0xdb,    '['},
  62.   {0xdc,    '\\'},
  63.   {0xdd,    ']'},
  64.   {'6',        '^'},
  65.   {0xbd,    '_'},
  66.   {0xc0,    '`'},
  67.   {0xdb,    '{'},
  68.   {0xdc,    '|'},
  69.   {0xdd,    '}'},
  70.   {0xc0,    '~'},
  71.   {VK_BACK,    FL_BackSpace},
  72.   {VK_TAB,    FL_Tab},
  73.   {VK_CLEAR,    0xff0b/*XK_Clear*/},
  74.   {VK_RETURN,    FL_Enter},
  75.   {VK_PAUSE,    FL_Pause},
  76.   {VK_SCROLL,    FL_Scroll_Lock},
  77.   {VK_ESCAPE,    FL_Escape},
  78.   {VK_HOME,    FL_Home},
  79.   {VK_LEFT,    FL_Left},
  80.   {VK_UP,    FL_Up},
  81.   {VK_RIGHT,    FL_Right},
  82.   {VK_DOWN,    FL_Down},
  83.   {VK_PRIOR,    FL_Page_Up},
  84.   {VK_NEXT,    FL_Page_Down},
  85.   {VK_END,    FL_End},
  86.   {VK_SNAPSHOT,    FL_Print},
  87.   {VK_INSERT,    FL_Insert},
  88.   {VK_APPS,    FL_Menu},
  89.   {VK_NUMLOCK,    FL_Num_Lock},
  90. //{VK_???,    FL_KP_Enter},
  91.   {VK_MULTIPLY,    FL_KP+'*'},
  92.   {VK_ADD,    FL_KP+'+'},
  93.   {VK_SUBTRACT,    FL_KP+'-'},
  94.   {VK_DECIMAL,    FL_KP+'.'},
  95.   {VK_DIVIDE,    FL_KP+'/'},
  96.   {VK_LSHIFT,    FL_Shift_L},
  97.   {VK_RSHIFT,    FL_Shift_R},
  98.   {VK_LCONTROL,    FL_Control_L},
  99.   {VK_RCONTROL,    FL_Control_R},
  100.   {VK_CAPITAL,    FL_Caps_Lock},
  101.   {VK_LWIN,    FL_Meta_L},
  102.   {VK_RWIN,    FL_Meta_R},
  103.   {VK_LMENU,    FL_Alt_L},
  104.   {VK_RMENU,    FL_Alt_R},
  105.   {VK_DELETE,    FL_Delete}
  106. };
  107.  
  108. static int fltk2ms(int fltk) {
  109.   if (fltk >= '0' && fltk <= '9') return fltk;
  110.   if (fltk >= 'A' && fltk <= 'Z') return fltk;
  111.   if (fltk >= 'a' && fltk <= 'z') return fltk-('a'-'A');
  112.   if (fltk > FL_F && fltk <= FL_F+16) return fltk-(FL_F-(VK_F1-1));
  113.   if (fltk >= FL_KP+'0' && fltk<=FL_KP+'9') return fltk-(FL_KP+'0'-VK_NUMPAD0);
  114.   int a = 0;
  115.   int b = sizeof(vktab)/sizeof(*vktab);
  116.   while (a < b) {
  117.     int c = (a+b)/2;
  118.     if (vktab[c].fltk == fltk) return vktab[c].vk;
  119.     if (vktab[c].fltk < fltk) a = c+1; else b = c;
  120.   }
  121.   return 0;
  122. }
  123.  
  124. int Fl::event_key(int k) {
  125.   return GetKeyState(fltk2ms(k))&~1;
  126. }
  127.  
  128. int Fl::get_key(int k) {
  129.   uchar foo[256];
  130.   GetKeyboardState(foo);
  131.   return foo[fltk2ms(k)]&~1;
  132. }
  133.  
  134. //
  135. // End of "$Id: Fl_get_key_win32.cxx,v 1.4.2.2 1999/09/16 05:34:26 bill Exp $".
  136. //
  137.