VirtualBox

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


Ignore:
Timestamp:
Jul 10, 2019 2:14:09 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131991
Message:

API: Added IKeyboard::putUsageCode method to send USB HID usage codes directly to the keyboard (see bugref:6026).

File:
1 edited

Legend:

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

    r76760 r79676  
    218218        return setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
    219219                            tr("Could not send all scan codes to the virtual keyboard (%Rrc)"),
     220                            vrc);
     221
     222    return S_OK;
     223}
     224
     225/**
     226 * Sends a HID usage code and page to the keyboard.
     227 *
     228 * @returns COM status code
     229 * @param aUsageCode    The HID usage code to send
     230 * @param aUsagePage    The HID usage page corresponding to the code
     231 * @param fKeyRelease   The key release flag
     232 */
     233HRESULT Keyboard::putUsageCode(LONG aUsageCode, LONG aUsagePage, BOOL fKeyRelease)
     234{
     235    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     236
     237    CHECK_CONSOLE_DRV(mpDrv[0]);
     238
     239    /* Send input to the last enabled device. Relies on the fact that
     240     * the USB keyboard is always initialized after the PS/2 keyboard.
     241     */
     242    PPDMIKEYBOARDPORT pUpPort = NULL;
     243    for (int i = KEYBOARD_MAX_DEVICES - 1; i >= 0 ; --i)
     244    {
     245        if (mpDrv[i] && (mpDrv[i]->u32DevCaps & KEYBOARD_DEVCAP_ENABLED))
     246        {
     247            pUpPort = mpDrv[i]->pUpPort;
     248            break;
     249        }
     250    }
     251
     252    /* No enabled keyboard - throw the input away. */
     253    if (!pUpPort)
     254        return S_OK;
     255
     256    int vrc = VINF_SUCCESS;
     257    uint32_t u32Usage;
     258    u32Usage = (uint8_t)aUsageCode | ((uint32_t)(uint8_t)aUsagePage << 16) | fKeyRelease ? 0x80000000 : 0;
     259    vrc = pUpPort->pfnPutEventHid(pUpPort, u32Usage);
     260    if (RT_FAILURE(vrc))
     261        return setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
     262                            tr("Could not send usage code to the virtual keyboard (%Rrc)"),
    220263                            vrc);
    221264
Note: See TracChangeset for help on using the changeset viewer.

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