Source code of Windows XP (NT5)
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.

129 lines
3.6 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. /*
  17. * Values for the second argument to MapVirtualKey, mysteriously
  18. * missing from windows.h.
  19. */
  20. #define MVK_OEMFROMVK 0
  21. #define MVK_VKFROMOEM 1
  22. /*
  23. * BEWARE! Converting a VK to a scan code and back again does not
  24. * necessarily get you back where you started! The main culprit
  25. * is the numeric keypad, since (for example) VK_LEFT and VK_NUMPAD4
  26. * both map to scan code 0x4B. We catch the numeric keypad specially
  27. * for exactly this purpose.
  28. *
  29. * The following table converts VK codes VK_NUMPAD0 through VK_NUMPAD9
  30. * to the corresponding VK_ code if NumLock is off.
  31. *
  32. * Note that this table and the loop that accesses it assume that the
  33. * scan codes VK_NUMPAD0 through VK_NUMPAD9 are consecutive.
  34. */
  35. WORD mpvkvk[10] = {
  36. VK_INSERT, /* VK_NUMPAD0 */
  37. VK_END, /* VK_NUMPAD1 */
  38. VK_DOWN, /* VK_NUMPAD2 */
  39. VK_NEXT, /* VK_NUMPAD3 */
  40. VK_LEFT, /* VK_NUMPAD4 */
  41. VK_CLEAR, /* VK_NUMPAD5 */
  42. VK_RIGHT, /* VK_NUMPAD6 */
  43. VK_HOME, /* VK_NUMPAD7 */
  44. VK_UP, /* VK_NUMPAD8 */
  45. VK_PRIOR, /* VK_NUMPAD9 */
  46. };
  47. /** HotKeyWindowsFromOem - Convert OEM hotkey into Windows hotkey
  48. *
  49. * INPUT
  50. * lppifkey -> PIFKEY describing OEM Hotkey
  51. *
  52. * OUTPUT
  53. * Windows hotkey value corresponding to lpwHotkey.
  54. */
  55. WORD HotKeyWindowsFromOem(LPCPIFKEY lppifkey)
  56. {
  57. WORD wHotKey = 0;
  58. if (lppifkey->Scan) {
  59. wHotKey = (WORD) MapVirtualKey(lppifkey->Scan, MVK_VKFROMOEM);
  60. if (lppifkey->Val & 2) {
  61. WORD vk;
  62. for (vk = VK_NUMPAD0; vk <= VK_NUMPAD9; vk++) {
  63. if (wHotKey == mpvkvk[vk - VK_NUMPAD0]) {
  64. wHotKey = vk; break;
  65. }
  66. }
  67. ASSERTTRUE(vk <= VK_NUMPAD9); /* Buggy PIF; do what we can */
  68. }
  69. if (lppifkey->Val & 1) wHotKey |= (HOTKEYF_EXT << 8);
  70. if (lppifkey->ShVal & (fPIFSh_RShf | fPIFSh_LShf))
  71. wHotKey |= (HOTKEYF_SHIFT << 8);
  72. if (lppifkey->ShVal & (fPIFSh_LCtrl|fPIFSh_RCtrl|fPIFSh_Ctrl))
  73. wHotKey |= (HOTKEYF_CONTROL << 8);
  74. if (lppifkey->ShVal & (fPIFSh_LAlt|fPIFSh_RAlt|fPIFSh_Alt))
  75. wHotKey |= (HOTKEYF_ALT << 8);
  76. }
  77. return wHotKey;
  78. }
  79. /** HotKeyOemFromWindows - Convert Windows hotkey into OEM hotkey
  80. *
  81. * INPUT
  82. * lppifkey -> struct PIF_Key to receive OEM hotkey
  83. * wHotKey = Windows hotkey
  84. *
  85. * OUTPUT
  86. * lppifkey filled with hotkey info
  87. */
  88. void HotKeyOemFromWindows(LPPIFKEY lppifkey, WORD wHotKey)
  89. {
  90. lppifkey->Scan = 0;
  91. lppifkey->ShVal = 0;
  92. lppifkey->ShMsk = 0;
  93. lppifkey->Val = 0;
  94. if (wHotKey) {
  95. lppifkey->Scan = (WORD) MapVirtualKey(LOBYTE(wHotKey), MVK_OEMFROMVK);
  96. lppifkey->ShMsk = fPIFSh_RShf | fPIFSh_LShf | fPIFSh_Ctrl | fPIFSh_Alt;
  97. if (wHotKey & (HOTKEYF_EXT << 8)) lppifkey->Val |= 1;
  98. /* Assumes that VK_NUMPAD0 through VK_NUMPAD9 are consecutive */
  99. if ((wHotKey - VK_NUMPAD0) < 10) lppifkey->Val |= 2;
  100. if (wHotKey & (HOTKEYF_SHIFT << 8))
  101. lppifkey->ShVal |= fPIFSh_RShf | fPIFSh_LShf;
  102. if (wHotKey & (HOTKEYF_CONTROL << 8))
  103. lppifkey->ShVal |= fPIFSh_Ctrl;
  104. if (wHotKey & (HOTKEYF_ALT << 8))
  105. lppifkey->ShVal |= fPIFSh_Alt;
  106. }
  107. }