Windows – Disable Sticky Keys with Registry Key doesn’t work

keyboardwindowswindows 7windows-registry

Before you vote this down, I'd like to say this now that the methods posted around the net doesn't work for me.

I've tried going to HKEY_CURRENT_USER\Control Panel\Accessibility\StickyKeys and changing the Flags to 10, 26, 250, 506, you name it, and it still doesn't disable it. BTW I'd like to disable both the popup that comes up AND the actual sticky key functionality.

Going to the Ease of Access part through the control panel and disabling there works, and I see the Flags being changed to 250 at HKEY_CURRENT_USER\Control Panel\Accessibility\StickyKeys , but if I enter 250 manually, it doesn't work. Therefore I'm thinking that the sticky keys setting must be saved somewhere else as well.

BTW I'm writing a program to disable sticky keys with registry keys, so I won't be able to use Ease of Access from the control panel.

So why does the registry key change work for other people around the net, and not me? I'm using Windows 7 64bit. Thanks.

Best Answer

I think this article should help you: http://msdn.microsoft.com/en-us/library/windows/desktop/ee416808(v=vs.85).aspx

If you look at the second example, you will see that it basically gives you what you want. You may put the code that's going to be below (Aside from the WinMain method) in a separate file and have your program call it.

STICKYKEYS g_StartupStickyKeys = {sizeof(STICKYKEYS), 0};
TOGGLEKEYS g_StartupToggleKeys = {sizeof(TOGGLEKEYS), 0};
FILTERKEYS g_StartupFilterKeys = {sizeof(FILTERKEYS), 0};    


INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
    // Save the current sticky/toggle/filter key settings so they can be restored them later
    SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(STICKYKEYS), &g_StartupStickyKeys, 0);
    SystemParametersInfo(SPI_GETTOGGLEKEYS, sizeof(TOGGLEKEYS), &g_StartupToggleKeys, 0);
    SystemParametersInfo(SPI_GETFILTERKEYS, sizeof(FILTERKEYS), &g_StartupFilterKeys, 0);

    // Disable when full screen
    AllowAccessibilityShortcutKeys( false );

    // Restore back when going to windowed or shutting down
    AllowAccessibilityShortcutKeys( true );
}


void AllowAccessibilityShortcutKeys( bool bAllowKeys )
{
    if( bAllowKeys )
    {
        // Restore StickyKeys/etc to original state and enable Windows key      
        STICKYKEYS sk = g_StartupStickyKeys;
        TOGGLEKEYS tk = g_StartupToggleKeys;
        FILTERKEYS fk = g_StartupFilterKeys;

        SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &g_StartupStickyKeys, 0);
        SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(TOGGLEKEYS), &g_StartupToggleKeys, 0);
        SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(FILTERKEYS), &g_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

        STICKYKEYS skOff = g_StartupStickyKeys;
        if( (skOff.dwFlags & SKF_STICKYKEYSON) == 0 )
        {
            // Disable the hotkey and the confirmation
            skOff.dwFlags &= ~SKF_HOTKEYACTIVE;
            skOff.dwFlags &= ~SKF_CONFIRMHOTKEY;

            SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &skOff, 0);
        }

        TOGGLEKEYS tkOff = g_StartupToggleKeys;
        if( (tkOff.dwFlags & TKF_TOGGLEKEYSON) == 0 )
        {
            // Disable the hotkey and the confirmation
            tkOff.dwFlags &= ~TKF_HOTKEYACTIVE;
            tkOff.dwFlags &= ~TKF_CONFIRMHOTKEY;

            SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(TOGGLEKEYS), &tkOff, 0);
        }

        FILTERKEYS fkOff = g_StartupFilterKeys;
        if( (fkOff.dwFlags & FKF_FILTERKEYSON) == 0 )
        {
            // Disable the hotkey and the confirmation
            fkOff.dwFlags &= ~FKF_HOTKEYACTIVE;
            fkOff.dwFlags &= ~FKF_CONFIRMHOTKEY;

            SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(FILTERKEYS), &fkOff, 0);
        }
    }
}

Hopefully this helps.

Related Question