You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.6KB

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