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.

126 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. DisableStickyKeys.cpp
  5. Abstract:
  6. This shim disables the Sticky Keys Accessibility Option at DLL_PROCESS_ATTACH,
  7. and re-enables it on termination of the application.
  8. Some applications, ie. A Bug's Life, have control keys mapped to the shift key. When the
  9. key is pressed five consecutive times the option is enabled and they are dumped out to the
  10. desktop to verify that they want to enable the option. In the case of A Bug's Life, the
  11. application errors and terminates when going to the desktop.
  12. History:
  13. 05/11/2000 jdoherty Created
  14. 11/06/2000 linstev Removed User32 dependency on InitializeHooks
  15. 04/01/2001 linstev Use SHIM_STATIC_DLLS_INITIALIZED callout
  16. --*/
  17. #include "precomp.h"
  18. IMPLEMENT_SHIM_BEGIN(DisableStickyKeys)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_END
  22. LPSTICKYKEYS g_lpOldStickyKeyValue;
  23. BOOL g_bInitialize = FALSE;
  24. /*++
  25. DisableStickyKeys saves the current value for LPSTICKYKEYS and then disables the option.
  26. --*/
  27. VOID
  28. DisableStickyKeys()
  29. {
  30. if (!g_bInitialize) {
  31. //
  32. // Disable sticky key support
  33. //
  34. g_bInitialize = TRUE;
  35. g_lpOldStickyKeyValue = (LPSTICKYKEYS) malloc(sizeof(STICKYKEYS));
  36. g_lpOldStickyKeyValue->cbSize = sizeof(STICKYKEYS);
  37. LPSTICKYKEYS pvParam = (LPSTICKYKEYS) malloc(sizeof(STICKYKEYS));
  38. pvParam->cbSize = sizeof(STICKYKEYS);
  39. pvParam->dwFlags = 0;
  40. SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(STICKYKEYS),
  41. g_lpOldStickyKeyValue, 0);
  42. SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), pvParam,
  43. SPIF_UPDATEINIFILE & SPIF_SENDCHANGE);
  44. LOGN( eDbgLevelInfo, "[DisableStickyKeys] Sticky keys disabled");
  45. }
  46. }
  47. /*++
  48. EnableStickyKeys uses the save value for STICKYKEYS and resets the option to the original setting.
  49. --*/
  50. VOID
  51. EnableStickyKeys()
  52. {
  53. if (g_bInitialize) {
  54. //
  55. // Restore sticky key state
  56. //
  57. SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS),
  58. g_lpOldStickyKeyValue, SPIF_UPDATEINIFILE & SPIF_SENDCHANGE);
  59. LOGN( eDbgLevelInfo, "[EnableStickyKeys] Sticky key state restored");
  60. }
  61. }
  62. BOOL
  63. NOTIFY_FUNCTION(
  64. DWORD fdwReason
  65. )
  66. {
  67. if (fdwReason == SHIM_STATIC_DLLS_INITIALIZED) {
  68. //
  69. // Turn OFF sticky keys
  70. //
  71. DisableStickyKeys();
  72. } else if (fdwReason == DLL_PROCESS_DETACH) {
  73. //
  74. // Restore sticky keys
  75. //
  76. EnableStickyKeys();
  77. }
  78. return TRUE;
  79. }
  80. /*++
  81. Register hooked functions
  82. --*/
  83. HOOK_BEGIN
  84. CALL_NOTIFY_FUNCTION
  85. HOOK_END
  86. IMPLEMENT_SHIM_END