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.

Comments (3)
  1. Murph says:

    Did you declare g_cyPage? (Maybe I missed it.)

  2. Mike Jackson says:

    Raymond,

    Ive just started going through this Scrollbar tutorial (excellent by the way!), but I can not see where you declare (or set) g_cyPage that is used in this and subsequent lessons.

  3. Raymond Chen says:

    Oops, g_cyPage should be g_cLinesPerPage.

Comments are closed.