VirtualBox

Changeset 89935 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Jun 29, 2021 6:38:48 AM (4 years ago)
Author:
vboxsync
Message:

Keyboard: Reworked the release-all-keys mechanism, made sure it's used before switching active keyboard, avoided potential mix-ups when tracking depressed keys (see bugref:10045).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/KeyboardImpl.cpp

    r85300 r89935  
    296296HRESULT Keyboard::releaseKeys()
    297297{
    298     std::vector<LONG> scancodes;
    299     scancodes.resize(1);
    300     scancodes[0] = 0xFC;    /* Magic scancode, see PS/2 and USB keyboard devices. */
    301     return putScancodes(scancodes, NULL);
     298    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     299
     300    /* Release all keys on the active keyboard in order to start with a clean slate.
     301     * Note that this should mirror the logic in Keyboard::putScancodes() when choosing
     302     * which keyboard to send the release event to.
     303     */
     304    PPDMIKEYBOARDPORT pUpPort = NULL;
     305    for (int i = KEYBOARD_MAX_DEVICES - 1; i >= 0 ; --i)
     306    {
     307        if (mpDrv[i] && (mpDrv[i]->u32DevCaps & KEYBOARD_DEVCAP_ENABLED))
     308        {
     309            pUpPort = mpDrv[i]->pUpPort;
     310            break;
     311        }
     312    }
     313
     314    if (pUpPort)
     315    {
     316        int rc = pUpPort->pfnReleaseKeys(pUpPort);
     317        if (RT_FAILURE(rc))
     318            AssertMsgFailed(("Failed to release keys on all keyboards! rc=%Rrc\n", rc));
     319    }
     320
     321    return S_OK;
    302322}
    303323
     
    352372{
    353373    PDRVMAINKEYBOARD pDrv = RT_FROM_MEMBER(pInterface, DRVMAINKEYBOARD, IConnector);
     374
     375    // Before activating a different keyboard, release all keys on the currently active one.
     376    if (fActive)
     377        pDrv->pKeyboard->releaseKeys();
     378
    354379    if (fActive)
    355380        pDrv->u32DevCaps |= KEYBOARD_DEVCAP_ENABLED;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette