Leaked source code of windows server 2003
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.

198 lines
6.0 KiB

  1. /*
  2. * Microsoft Confidential
  3. * Copyright (C) Microsoft Corporation 1991
  4. * All Rights Reserved.
  5. *
  6. *
  7. * PIFHOT.C
  8. * User interface routines for hot-keys
  9. *
  10. * History:
  11. * Created 21-Dec-1992 5:30pm by Jeff Parsons (based on old PIFEDIT code)
  12. * Rewritten 25-Dec-1993 by Raymond Chen
  13. */
  14. #include "shellprv.h"
  15. #pragma hdrstop
  16. #ifdef _X86_
  17. /*
  18. * Values for the second argument to MapVirtualKey, mysteriously
  19. * missing from windows.h.
  20. */
  21. #define MVK_OEMFROMVK 0
  22. #define MVK_VKFROMOEM 1
  23. /*
  24. * BEWARE! Converting a VK to a scan code and back again does not
  25. * necessarily get you back where you started! The main culprit
  26. * is the numeric keypad, since (for example) VK_LEFT and VK_NUMPAD4
  27. * both map to scan code 0x4B. We catch the numeric keypad specially
  28. * for exactly this purpose.
  29. *
  30. * The following table converts VK codes VK_NUMPAD0 through VK_NUMPAD9
  31. * to the corresponding VK_ code if NumLock is off.
  32. *
  33. * Note that this table and the loop that accesses it assume that the
  34. * scan codes VK_NUMPAD0 through VK_NUMPAD9 are consecutive.
  35. */
  36. WORD mpvkvk[10] = {
  37. VK_INSERT, /* VK_NUMPAD0 */
  38. VK_END, /* VK_NUMPAD1 */
  39. VK_DOWN, /* VK_NUMPAD2 */
  40. VK_NEXT, /* VK_NUMPAD3 */
  41. VK_LEFT, /* VK_NUMPAD4 */
  42. VK_CLEAR, /* VK_NUMPAD5 */
  43. VK_RIGHT, /* VK_NUMPAD6 */
  44. VK_HOME, /* VK_NUMPAD7 */
  45. VK_UP, /* VK_NUMPAD8 */
  46. VK_PRIOR, /* VK_NUMPAD9 */
  47. };
  48. /*
  49. * PIF_Ky_Val
  50. * = 1, if extended code (key is an extended code only)
  51. * = 0FFh, if either (key is EITHER extended or not extended)
  52. * = 0 if not extended (key is not extended only)
  53. *
  54. * bit 15 - Ins depressed
  55. * bit 14 - Caps Lock depressed
  56. * bit 13 - Num Lock depressed
  57. * bit 12 - Scroll Lock depressed
  58. * bit 11 - hold state active(Ctrl-Num Lock)
  59. * bit 10 - 0
  60. * bit 9 - 0
  61. * bit 8 - 0
  62. * bit 7 - Insert state active
  63. * bit 6 - Caps Lock state active
  64. * bit 5 - Num Lock state active
  65. * bit 4 - Scroll Lock state active
  66. * bit 3 - Alt shift depressed
  67. * bit 2 - Ctrl shift depressed
  68. * bit 1 - left shift depressed
  69. * bit 0 - right shift depressed
  70. */
  71. #define fPIFSh_RShf 0x0001 /* Right shift key */
  72. #define fPIFSh_RShfBit 0
  73. #define fPIFSh_LShf 0x0002 /* Left shift key */
  74. #define fPIFSh_LShfBit 1
  75. #define fPIFSh_Ctrl 0x0004 /* Either Control shift key */
  76. #define fPIFSh_CtrlBit 2
  77. #define fPIFSh_Alt 0x0008 /* Either Alt shift key */
  78. #define fPIFSh_AltBit 3
  79. #define fPIFSh_ScLok 0x0010 /* Scroll lock active */
  80. #define fPIFSh_ScLokBit 4
  81. #define fPIFSh_NmLok 0x0020 /* Num lock active */
  82. #define fPIFSh_NmLokBit 5
  83. #define fPIFSh_CpLok 0x0040 /* Caps lock active */
  84. #define fPIFSh_CpLokBit 6
  85. #define fPIFSh_Insrt 0x0080 /* Insert active */
  86. #define fPIFSh_InsrtBit 7
  87. #define fPIFSh_Ext0 0x0400 /* Extended K/B shift */
  88. #define fPIFSh_Ext0Bit 10
  89. #define fPIFSh_Hold 0x0800 /* Ctrl-Num-Lock/Pause active */
  90. #define fPIFSh_HoldBit 11
  91. #define fPIFSh_LAlt 0x1000 /* Left Alt key is down */
  92. #define fPIFSh_LAltBit 12
  93. #define fPIFSh_RAlt 0x2000 /* Right Alt key is down */
  94. #define fPIFSh_RAltBit 13
  95. #define fPIFSh_LCtrl 0x4000 /* Left Ctrl key is down */
  96. #define fPIFSh_LCtrlBit 14
  97. #define fPIFSh_RCtrl 0x8000 /* Right Ctrl key is down */
  98. #define fPIFSh_RCtrlBit 15
  99. /** HotKeyWindowsFromOem - Convert OEM hotkey into Windows hotkey
  100. *
  101. * INPUT
  102. * lppifkey -> PIFKEY describing OEM Hotkey
  103. *
  104. * OUTPUT
  105. * Windows hotkey value corresponding to lpwHotkey.
  106. */
  107. WORD HotKeyWindowsFromOem(LPCPIFKEY lppifkey)
  108. {
  109. WORD wHotKey = 0;
  110. if (lppifkey->Scan) {
  111. wHotKey = (WORD) MapVirtualKey(lppifkey->Scan, MVK_VKFROMOEM);
  112. if (lppifkey->Val & 2) {
  113. WORD vk;
  114. for (vk = VK_NUMPAD0; vk <= VK_NUMPAD9; vk++) {
  115. if (wHotKey == mpvkvk[vk - VK_NUMPAD0]) {
  116. wHotKey = vk; break;
  117. }
  118. }
  119. ASSERTTRUE(vk <= VK_NUMPAD9); /* Buggy PIF; do what we can */
  120. }
  121. if (lppifkey->Val & 1) wHotKey |= (HOTKEYF_EXT << 8);
  122. if (lppifkey->ShVal & (fPIFSh_RShf | fPIFSh_LShf))
  123. wHotKey |= (HOTKEYF_SHIFT << 8);
  124. if (lppifkey->ShVal & (fPIFSh_LCtrl|fPIFSh_RCtrl|fPIFSh_Ctrl))
  125. wHotKey |= (HOTKEYF_CONTROL << 8);
  126. if (lppifkey->ShVal & (fPIFSh_LAlt|fPIFSh_RAlt|fPIFSh_Alt))
  127. wHotKey |= (HOTKEYF_ALT << 8);
  128. }
  129. return wHotKey;
  130. }
  131. /** HotKeyOemFromWindows - Convert Windows hotkey into OEM hotkey
  132. *
  133. * INPUT
  134. * lppifkey -> struct PIF_Key to receive OEM hotkey
  135. * wHotKey = Windows hotkey
  136. *
  137. * OUTPUT
  138. * lppifkey filled with hotkey info
  139. */
  140. void HotKeyOemFromWindows(LPPIFKEY lppifkey, WORD wHotKey)
  141. {
  142. lppifkey->Scan = 0;
  143. lppifkey->ShVal = 0;
  144. lppifkey->ShMsk = 0;
  145. lppifkey->Val = 0;
  146. if (wHotKey) {
  147. lppifkey->Scan = (WORD) MapVirtualKey(LOBYTE(wHotKey), MVK_OEMFROMVK);
  148. lppifkey->ShMsk = fPIFSh_RShf | fPIFSh_LShf | fPIFSh_Ctrl | fPIFSh_Alt;
  149. if (wHotKey & (HOTKEYF_EXT << 8)) lppifkey->Val |= 1;
  150. /* Assumes that VK_NUMPAD0 through VK_NUMPAD9 are consecutive */
  151. if ((wHotKey - VK_NUMPAD0) < 10) lppifkey->Val |= 2;
  152. if (wHotKey & (HOTKEYF_SHIFT << 8))
  153. lppifkey->ShVal |= fPIFSh_RShf | fPIFSh_LShf;
  154. if (wHotKey & (HOTKEYF_CONTROL << 8))
  155. lppifkey->ShVal |= fPIFSh_Ctrl;
  156. if (wHotKey & (HOTKEYF_ALT << 8))
  157. lppifkey->ShVal |= fPIFSh_Alt;
  158. }
  159. }
  160. #endif