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.

137 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 2000-2002 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. 02/06/2002 mnikkel Added check for malloc and SystemParametersInfo failures.
  17. --*/
  18. #include "precomp.h"
  19. IMPLEMENT_SHIM_BEGIN(DisableStickyKeys)
  20. #include "ShimHookMacro.h"
  21. APIHOOK_ENUM_BEGIN
  22. APIHOOK_ENUM_END
  23. STICKYKEYS g_OldStickyKeyValue;
  24. BOOL g_bInitialize2 = FALSE;
  25. /*++
  26. DisableStickyKeys saves the current value for LPSTICKYKEYS and then disables the option.
  27. --*/
  28. VOID
  29. DisableStickyKeys()
  30. {
  31. if (!g_bInitialize2)
  32. {
  33. STICKYKEYS NewStickyKeyValue;
  34. // Initialize the current and new Stickykey structures
  35. g_OldStickyKeyValue.cbSize = sizeof(STICKYKEYS);
  36. NewStickyKeyValue.cbSize = sizeof(STICKYKEYS);
  37. NewStickyKeyValue.dwFlags = 0;
  38. // retrieve the current Stickykey structure
  39. if (SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(STICKYKEYS), &g_OldStickyKeyValue, 0))
  40. {
  41. // if retrieval of current Stickykey structure was successful then broadcast the settings
  42. // with the new structure. This does NOT modify the INI file.
  43. if (SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &NewStickyKeyValue, SPIF_SENDCHANGE))
  44. {
  45. g_bInitialize2 = TRUE;
  46. LOGN( eDbgLevelInfo, "[DisableStickyKeys] Stickykeys disabled.");
  47. }
  48. else
  49. {
  50. LOGN( eDbgLevelError, "[DisableStickyKeys] Unable to change Stickykey settings!");
  51. }
  52. }
  53. else
  54. {
  55. LOGN( eDbgLevelError, "[DisableStickyKeys] Unable to retrieve current Stickykey settings!");
  56. }
  57. }
  58. }
  59. /*++
  60. EnableStickyKeys uses the save value for STICKYKEYS and resets the option to the original setting.
  61. --*/
  62. VOID
  63. EnableStickyKeys()
  64. {
  65. if (g_bInitialize2)
  66. {
  67. g_bInitialize2 = FALSE;
  68. // Restore Stickykey original state
  69. if (SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &g_OldStickyKeyValue, SPIF_SENDCHANGE))
  70. {
  71. LOGN( eDbgLevelInfo, "[DisableStickyKeys] Sticky key state restored");
  72. }
  73. else
  74. {
  75. LOGN( eDbgLevelError, "[DisableStickyKeys] Unable to restore Sticky key settings!");
  76. }
  77. }
  78. }
  79. BOOL
  80. NOTIFY_FUNCTION(
  81. DWORD fdwReason
  82. )
  83. {
  84. if (fdwReason == SHIM_STATIC_DLLS_INITIALIZED)
  85. {
  86. // Turn OFF sticky keys
  87. DisableStickyKeys();
  88. } else if (fdwReason == DLL_PROCESS_DETACH)
  89. {
  90. // Restore sticky keys
  91. EnableStickyKeys();
  92. }
  93. return TRUE;
  94. }
  95. /*++
  96. Register hooked functions
  97. --*/
  98. HOOK_BEGIN
  99. CALL_NOTIFY_FUNCTION
  100. HOOK_END
  101. IMPLEMENT_SHIM_END