August 5th, 2003

Keyboard accessibility for scrollbars

Note that so far, the scrollbar is accessible only with the mouse. Our next step is to add keyboard access to the scrollbar. Fortunately, this is not all that difficult. We merely map some keystrokes to equivalent scrollbar actions.

void OnKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags)
{
    if (fDown) {
        switch (vk) {
        case VK_UP:         ScrollDelta(hwnd, -cRepeat); break;
        case VK_DOWN:       ScrollDelta(hwnd, +cRepeat); break;
        case VK_PRIOR:      ScrollDelta(hwnd, -cRepeat*g_cyPage); break;
        case VK_NEXT:       ScrollDelta(hwnd, +cRepeat*g_cyPage); break;
        case VK_HOME:       ScrollTo(hwnd, 0); break;
        case VK_END:        ScrollTo(hwnd, MAXLONG); break;
        }
    }
}
    /* Add to WndProc */
    HANDLE_MSG(hwnd, WM_KEYDOWN, OnKey);

Note that this doesn’t make our sample program fully accessible; this just makes the scrollbars accessible. Full accessibility will be covered in a (much) later blog entry. Right now, I’m just focusing on scrollbars.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.