VirtualBox

Changeset 62396 in vbox for trunk


Ignore:
Timestamp:
Jul 21, 2016 1:16:07 PM (8 years ago)
Author:
vboxsync
Message:

bugref:6947: FE/Qt: Problem with "Alt" key up event in Windows guests when "Alt-Tab"-ing away from guest: switch from injecting a fixed key sequence to injecting the modifier keys from the host sequence when we remove focus from a virtual machine and a key is pressed. We do this before the key release event. The idea is specifically so that switching away from the machine with alt-tab will not cause the guest to see a single alt key press and release, and activate a menu in some guest application. We switched to using the host sequence because the user can choose it to be something which will not cause problems in the guest.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp

    r62154 r62396  
    525525     * This is just a work-around and is likely to fail in some cases.  We are
    526526     * not aware of any ideal solution.  Historically we sent an 0xFE scan code,
    527      * but this is a real key release code on Brazilian keyboards. */
     527     * but this is a real key release code on Brazilian keyboards. Now we send
     528     * a sequence of all modifier keys contained in the host sequence, hoping
     529     * that the user will choose something which the guest does not interpret. */
    528530    for (uint i = 0; i < SIZEOF_ARRAY (m_pressedKeys); i++)
    529531    {
     
    532534            if (!fSentRESEND)
    533535            {
    534                 LONG aCodes[] = { 0x1D,  0x2A, 0x38, 0x9D, 0xAA, 0xB8 };
    535                 QVector <LONG> codes(RT_ELEMENTS(aCodes));
    536                 for (unsigned i = 0; i < RT_ELEMENTS(aCodes); ++i)
    537                     codes[i] = aCodes[i];
     536                QList <unsigned> shortCodes = UIHostCombo::modifiersToScanCodes(m_globalSettings.hostCombo());
     537                QVector <LONG> codes;
     538                foreach (unsigned idxCode, shortCodes)
     539                {
     540                    if (idxCode & 0x100)
     541                        codes << 0xE0;
     542                    codes << (idxCode & 0x7F);
     543                    m_pressedKeys[idxCode & 0x7F] &= idxCode & 0x100 ? ~IsExtKeyPressed : ~IsKeyPressed;
     544                }
     545                foreach (unsigned idxCode, shortCodes)
     546                {
     547                    if (idxCode & 0x100)
     548                        codes << 0xE0;
     549                    codes << ((idxCode & 0x7F) | 0x80);
     550                }
    538551                keyboard().PutScancodes(codes);
    539                 m_pressedKeys[0x1D] = m_pressedKeys[0x2A] = m_pressedKeys[0x38] = 0;
    540552                fSentRESEND = true;
    541553            }
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.cpp

    r62358 r62396  
    5757#elif defined(VBOX_WS_X11)
    5858# include "XKeyboard.h"
     59#endif /* VBOX_WS_X11 */
     60
     61/* Other VBox includes: */
     62#if defined(VBOX_WS_X11)
     63# include <VBox/VBoxKeyboard.h>
    5964#endif /* VBOX_WS_X11 */
    6065
     
    276281}
    277282
     283unsigned UINativeHotKey::modifierToSet1ScanCode(int iKeyCode)
     284{
     285    switch(iKeyCode)
     286    {
     287#if defined(VBOX_WS_MAC)
     288
     289        case controlKey:                        return 0x1D;
     290        case rightControlKey:                   return 0x11D;
     291        case shiftKey:                          return 0x2A;
     292        case rightShiftKey:                     return 0x36;
     293        case optionKey:                         return 0x38;
     294        case rightOptionKey:                    return 0x138;
     295        case cmdKey:                            return 0x15B;
     296        case kEventKeyModifierRightCmdKeyMask:  return 0x15C;
     297        default:                                return 0;
     298
     299#elif defined(VBOX_WS_WIN)
     300
     301        case VK_CONTROL:
     302        case VK_LCONTROL:  return 0x1D;
     303        case VK_RCONTROL:  return 0x11D;
     304        case VK_SHIFT:
     305        case VK_LSHIFT:    return 0x2A;
     306        case VK_RSHIFT:    return 0x36;
     307        case VK_MENU:
     308        case VK_LMENU:     return 0x38;
     309        case VK_RMENU:     return 0x138;
     310        case VK_LWIN:      return 0x15B;
     311        case VK_RWIN:      return 0x15C;
     312        case VK_APPS:      return 0x15D;
     313        default:           return 0;
     314
     315#elif defined(VBOX_WS_X11)
     316
     317        case XK_Control_L:         return 0x1D;
     318        case XK_Control_R:         return 0x11D;
     319        case XK_Shift_L:           return 0x2A;
     320        case XK_Shift_R:           return 0x36;
     321        case XK_Alt_L:             return 0x38;
     322        case XK_ISO_Level3_Shift:
     323        case XK_Alt_R:             return 0x138;
     324        case XK_Meta_L:
     325        case XK_Super_L:           return 0x15B;
     326        case XK_Meta_R:
     327        case XK_Super_R:           return 0x15C;
     328        case XK_Menu:              return 0x15D;
     329        default:                   return 0;
     330
     331#else
     332
     333# warning "port me!"
     334
     335        default:  return 0;
     336
     337#endif
     338    }
     339}
     340
    278341#if defined(VBOX_WS_WIN)
    279342
     
    380443            keyCodeList << iKeyCode;
    381444    return keyCodeList;
     445}
     446
     447QList<unsigned> UIHostCombo::modifiersToScanCodes(const QString &strKeyCombo)
     448{
     449    QStringList encodedKeyList = strKeyCombo.split(',');
     450    QList<unsigned> scanCodeList;
     451    for (int i = 0; i < encodedKeyList.size(); ++i)
     452        if (unsigned idxScanCode = UINativeHotKey::modifierToSet1ScanCode(encodedKeyList[i].toInt()))
     453            if (idxScanCode != 0)
     454                scanCodeList << idxScanCode;
     455    return scanCodeList;
    382456}
    383457
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h

    r60362 r62396  
    4747    QString toString(int iKeyCode);
    4848    bool isValidKey(int iKeyCode);
     49    /** Translates a modifier key in host platform
     50      * encoding to the corresponding set 1 PC scan code.
     51      * @note  Non-modifier keys will return zero. */
     52    unsigned modifierToSet1ScanCode(int iKeyCode);
    4953#if defined(VBOX_WS_WIN)
    5054    int distinguishModifierVKey(int wParam, int lParam);
     
    6367    QString toReadableString(const QString &strKeyCombo);
    6468    QList<int> toKeyCodeList(const QString &strKeyCombo);
     69    /** Returns a sequence of the set 1 PC scan codes for all
     70      * modifiers contained in the (host platform format) sequence passed. */
     71    QList<unsigned> modifiersToScanCodes(const QString &strKeyCombo);
    6572    bool isValidKeyCombo(const QString &strKeyCombo);
    6673}
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