/// <summary> /// False to stop the sticky keys popup. /// True to return to whatever the system has been set to. /// </summary> public static void AllowAccessibilityShortcutKeys(bool bAllowKeys) { if (!StartupAccessibilitySet) { StartupStickyKeys.cbSize = SKEYSize; StartupToggleKeys.cbSize = SKEYSize; StartupFilterKeys.cbSize = FKEYSize; SystemParametersInfo(SPI_GETSTICKYKEYS, SKEYSize, ref StartupStickyKeys, 0); SystemParametersInfo(SPI_GETTOGGLEKEYS, SKEYSize, ref StartupToggleKeys, 0); SystemParametersInfo(SPI_GETFILTERKEYS, FKEYSize, ref StartupFilterKeys, 0); StartupAccessibilitySet = true; } if (bAllowKeys) { // Restore StickyKeys/etc to original state and enable Windows key SystemParametersInfo(SPI_SETSTICKYKEYS, SKEYSize, ref StartupStickyKeys, 0); SystemParametersInfo(SPI_SETTOGGLEKEYS, SKEYSize, ref StartupToggleKeys, 0); SystemParametersInfo(SPI_SETFILTERKEYS, FKEYSize, ref StartupFilterKeys, 0); } else { // Disable StickyKeys/etc shortcuts but if the accessibility feature is on, // then leave the settings alone as its probably being usefully used SKEY skOff = StartupStickyKeys; if ((skOff.dwFlags & SKF_STICKYKEYSON) == 0) { // Disable the hotkey and the confirmation skOff.dwFlags &= ~SKF_HOTKEYACTIVE; skOff.dwFlags &= ~SKF_CONFIRMHOTKEY; SystemParametersInfo(SPI_SETSTICKYKEYS, SKEYSize, ref skOff, 0); } SKEY tkOff = StartupToggleKeys; if ((tkOff.dwFlags & TKF_TOGGLEKEYSON) == 0) { // Disable the hotkey and the confirmation tkOff.dwFlags &= ~TKF_HOTKEYACTIVE; tkOff.dwFlags &= ~TKF_CONFIRMHOTKEY; SystemParametersInfo(SPI_SETTOGGLEKEYS, SKEYSize, ref tkOff, 0); } FILTERKEY fkOff = StartupFilterKeys; if ((fkOff.dwFlags & FKF_FILTERKEYSON) == 0) { // Disable the hotkey and the confirmation fkOff.dwFlags &= ~FKF_HOTKEYACTIVE; fkOff.dwFlags &= ~FKF_CONFIRMHOTKEY; SystemParametersInfo(SPI_SETFILTERKEYS, FKEYSize, ref fkOff, 0); } } }
public static void AllowAccessibilityShortcutKeys(bool bAllowKeys) { if (!StartupAccessibilitySet) { StartupStickyKeys.cbSize = SKEYSize; StartupToggleKeys.cbSize = SKEYSize; StartupFilterKeys.cbSize = FKEYSize; SystemParametersInfo(SPI_GETSTICKYKEYS, SKEYSize, ref StartupStickyKeys, 0); SystemParametersInfo(SPI_GETTOGGLEKEYS, SKEYSize, ref StartupToggleKeys, 0); SystemParametersInfo(SPI_GETFILTERKEYS, FKEYSize, ref StartupFilterKeys, 0); StartupAccessibilitySet = true; } if (bAllowKeys) { SystemParametersInfo(SPI_SETSTICKYKEYS, SKEYSize, ref StartupStickyKeys, 0); SystemParametersInfo(SPI_SETTOGGLEKEYS, SKEYSize, ref StartupToggleKeys, 0); SystemParametersInfo(SPI_SETFILTERKEYS, FKEYSize, ref StartupFilterKeys, 0); } else { SKEY skOff = StartupStickyKeys; if ((skOff.dwFlags & SKF_STICKYKEYSON) == 0) { skOff.dwFlags &= ~SKF_HOTKEYACTIVE; skOff.dwFlags &= ~SKF_CONFIRMHOTKEY; SystemParametersInfo(SPI_SETSTICKYKEYS, SKEYSize, ref skOff, 0); } SKEY tkOff = StartupToggleKeys; if ((tkOff.dwFlags & TKF_TOGGLEKEYSON) == 0) { tkOff.dwFlags &= ~TKF_HOTKEYACTIVE; tkOff.dwFlags &= ~TKF_CONFIRMHOTKEY; SystemParametersInfo(SPI_SETTOGGLEKEYS, SKEYSize, ref tkOff, 0); } FILTERKEY fkOff = StartupFilterKeys; if ((fkOff.dwFlags & FKF_FILTERKEYSON) == 0) { fkOff.dwFlags &= ~FKF_HOTKEYACTIVE; fkOff.dwFlags &= ~FKF_CONFIRMHOTKEY; SystemParametersInfo(SPI_SETFILTERKEYS, FKEYSize, ref fkOff, 0); } } }
private static extern bool SystemParametersInfo(uint action, uint param, ref SKEY vparam, uint init);