Changeset 59372 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Jan 18, 2016 9:24:42 AM (9 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
r59361 r59372 639 639 bool UIKeyboardHandler::winEventFilter(MSG *pMsg, ulong uScreenId) 640 640 { 641 /* Check if some system event should be filtered-out. 642 * Returning 'true' means filtering-out, 643 * Returning 'false' means passing event to Qt. */ 644 bool fResult = false; /* Pass to Qt by default: */ 645 646 /* Skip this event if m_fSkipKeyboardEvents is set by winSkipKeyboardEvents(). */ 641 /* Ignore this event if m_fSkipKeyboardEvents is set by winSkipKeyboardEvents(). */ 647 642 if (m_fSkipKeyboardEvents) 648 643 return false; 649 644 645 /* Check if some system event should be filtered out. 646 * Returning @c true means filtering-out, 647 * Returning @c false means passing event to Qt. */ 648 bool fResult = false; /* Pass to Qt by default. */ 649 650 /* Depending on message type: */ 650 651 switch (pMsg->message) 651 652 { 653 /* Watch for key-events: */ 652 654 case WM_KEYDOWN: 653 655 case WM_KEYUP: … … 655 657 case WM_SYSKEYUP: 656 658 { 657 /* Check for the special flag possibly set at the end of this function: */ 659 /* Check for our own special flag to ignore this event. 660 * That flag could only be set later in this function 661 * so having it here means this event came here 662 * for the second time already. */ 658 663 if (pMsg->lParam & (0x1 << 25)) 659 664 { 665 /* Remove that flag as well: */ 660 666 pMsg->lParam &= ~(0x1 << 25); 661 667 fResult = false; … … 663 669 } 664 670 665 /* Scan codes 0x80 and 0x00 are ignored: */666 unsigned scan = (pMsg->lParam >> 16) & 0x7F;667 if (! scan)671 /* Scan codes 0x80 and 0x00 should be filtered out: */ 672 unsigned uScan = (pMsg->lParam >> 16) & 0x7F; 673 if (!uScan) 668 674 { 669 675 fResult = true; … … 671 677 } 672 678 673 int vkey = pMsg->wParam; 674 675 int flags = 0; 679 /* Get the virtual key: */ 680 int iVKey = pMsg->wParam; 681 682 /* Calculate flags: */ 683 int iFlags = 0; 676 684 if (pMsg->lParam & 0x1000000) 677 flags |= KeyExtended;685 iFlags |= KeyExtended; 678 686 if (!(pMsg->lParam & 0x80000000)) 679 flags |= KeyPressed;680 681 /* If present - why not just assert this?*/682 if (m_pAltGrMonitor)683 { 684 /* Bail out if we are sure that this is a fake left control.*/685 if (m_pAltGrMonitor->isCurrentEventDefinitelyFake( scan, flags & KeyPressed, flags & KeyExtended))687 iFlags |= KeyPressed; 688 689 /* Make sure AltGr monitor exists: */ 690 AssertPtrReturn(m_pAltGrMonitor, false); 691 { 692 /* Filter event out if we are sure that this is a fake left control event: */ 693 if (m_pAltGrMonitor->isCurrentEventDefinitelyFake(uScan, iFlags & KeyPressed, iFlags & KeyExtended)) 686 694 { 687 695 fResult = true; … … 689 697 } 690 698 /* Update AltGR monitor state from key-event: */ 691 m_pAltGrMonitor->updateStateFromKeyEvent( scan, flags & KeyPressed, flags & KeyExtended);699 m_pAltGrMonitor->updateStateFromKeyEvent(uScan, iFlags & KeyPressed, iFlags & KeyExtended); 692 700 /* And release left Ctrl key early (if required): */ 693 701 if (m_pAltGrMonitor->isLeftControlReleaseNeeded()) … … 696 704 697 705 /* Check for special Korean keys. Based on the keyboard layout selected 698 * on the host, the scan code in lParam might be 0x71/0x72 or 0xF1/0xF2.699 * In either case, we must deliver 0xF1/0xF2 scan code to the guest when706 * on the host, the scan code in lParam might be 0x71/0x72 or 0xF1/0xF2. 707 * In either case, we must deliver 0xF1/0xF2 scan code to the guest when 700 708 * the key is pressed and nothing when it's released. */ 701 if ( scan == 0x71 || scan == 0x72)702 { 703 scan |= 0x80;704 flags = KeyPressed;/* Because a release would be ignored. */705 vkey = VK_PROCESSKEY; /* In case it was 0xFF*/709 if (uScan == 0x71 || uScan == 0x72) 710 { 711 uScan |= 0x80; 712 iFlags = KeyPressed; /* Because a release would be ignored. */ 713 iVKey = VK_PROCESSKEY; /* In case it was 0xFF. */ 706 714 } 707 715 708 716 /* When one of the SHIFT keys is held and one of the cursor movement 709 717 * keys is pressed, Windows duplicates SHIFT press/release messages, 710 * but with the virtual key 711 * sent in some other situations (Pause, PrtScn, etc.). Ignore sucmessages. */712 if ( vkey == 0xFF)718 * but with the virtual keycode set to 0xFF. These virtual keys are also 719 * sent in some other situations (Pause, PrtScn, etc.). Filter out such messages. */ 720 if (iVKey == 0xFF) 713 721 { 714 722 fResult = true; … … 716 724 } 717 725 718 switch (vkey) 726 /* Handle special virtual keys: */ 727 switch (iVKey) 719 728 { 720 729 case VK_SHIFT: … … 723 732 { 724 733 /* Overcome Win32 modifier key generalization: */ 725 int keyscan = scan;726 if ( flags & KeyExtended)727 keyscan |= 0xE000;728 switch ( keyscan)734 int iKeyscan = uScan; 735 if (iFlags & KeyExtended) 736 iKeyscan |= 0xE000; 737 switch (iKeyscan) 729 738 { 730 case 0x002A: vkey = VK_LSHIFT;break;731 case 0x0036: vkey = VK_RSHIFT;break;732 case 0x001D: vkey = VK_LCONTROL; break;733 case 0xE01D: vkey = VK_RCONTROL; break;734 case 0x0038: vkey = VK_LMENU;break;735 case 0xE038: vkey = VK_RMENU;break;739 case 0x002A: iVKey = VK_LSHIFT; break; 740 case 0x0036: iVKey = VK_RSHIFT; break; 741 case 0x001D: iVKey = VK_LCONTROL; break; 742 case 0xE01D: iVKey = VK_RCONTROL; break; 743 case 0x0038: iVKey = VK_LMENU; break; 744 case 0xE038: iVKey = VK_RMENU; break; 736 745 } 737 746 break; … … 739 748 case VK_NUMLOCK: 740 749 /* Win32 sets the extended bit for the NumLock key. Reset it: */ 741 flags &= ~KeyExtended;750 iFlags &= ~KeyExtended; 742 751 break; 743 752 case VK_SNAPSHOT: 744 flags |= KeyPrint;753 iFlags |= KeyPrint; 745 754 break; 746 755 case VK_PAUSE: 747 flags |= KeyPause;756 iFlags |= KeyPause; 748 757 break; 749 758 } 750 759 751 bool result = keyEvent(vkey, scan, flags, uScreenId); 760 /* Finally, handle parsed key-event: */ 761 fResult = keyEvent(iVKey, uScan, iFlags, uScreenId); 762 752 763 /* Always let Windows see key releases to prevent stuck keys. 753 764 * Hopefully this won't cause any other issues. */ … … 757 768 break; 758 769 } 759 if (!result && m_fIsKeyboardCaptured) 760 { 761 /* keyEvent() returned that it didn't process the message, but since the 762 * keyboard is captured, we don't want to pass it to Windows. We just want 763 * to let Qt process the message (to handle non-alphanumeric <HOST>+key 764 * shortcuts for example). So send it directly to the window with the 765 * special flag in the reserved area of lParam (to avoid recursion). */ 770 771 /* Above keyEvent() returned that it didn't processed the event, but since the 772 * keyboard is captured, we don't want to pass it to Windows. We just want 773 * to let Qt process the message (to handle non-alphanumeric <HOST>+key 774 * shortcuts for example). So send it directly to the window with the 775 * special flag in the reserved area of lParam (to avoid recursion). */ 776 if (!fResult && m_fIsKeyboardCaptured) 777 { 766 778 ::SendMessage(pMsg->hwnd, pMsg->message, 767 779 pMsg->wParam, pMsg->lParam | (0x1 << 25)); … … 771 783 772 784 /* These special keys have to be handled by Windows as well to update the 773 * internal modifier state and to enable/disable the keyboard LED */774 if ( vkey == VK_NUMLOCK || vkey == VK_CAPITAL || vkey == VK_LSHIFT || vkey == VK_RSHIFT)785 * internal modifier state and to enable/disable the keyboard LED: */ 786 if (iVKey == VK_NUMLOCK || iVKey == VK_CAPITAL || iVKey == VK_LSHIFT || iVKey == VK_RSHIFT) 775 787 { 776 788 fResult = false; … … 778 790 } 779 791 780 fResult = result;781 792 break; 782 793 } … … 784 795 break; 785 796 } 797 786 798 /* Return result: */ 787 799 return fResult; … … 1416 1428 #elif defined(Q_WS_WIN) 1417 1429 1430 /* static */ 1418 1431 LRESULT CALLBACK UIKeyboardHandler::winKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) 1419 1432 { 1433 /* All keyboard class events needs to be handled: */ 1420 1434 if (nCode == HC_ACTION && m_spKeyboardHandler && m_spKeyboardHandler->winKeyboardEvent(wParam, *(KBDLLHOOKSTRUCT*)lParam)) 1421 1435 return 1; 1422 1436 1437 /* Pass the event along: */ 1423 1438 return CallNextHookEx(NULL, nCode, wParam, lParam); 1424 1439 } … … 1455 1470 return true; 1456 1471 1472 /* Compose the MSG: */ 1457 1473 MSG message; 1458 1474 message.hwnd = (HWND)m_views[m_iKeyboardHookViewIndex]->winId(); … … 1466 1482 message.lParam &= ~0x1000000; 1467 1483 1468 /* We suppose here that this hook is always called on the main GUI thread */ 1484 /* Pass event to view's event handler: */ 1485 #if QT_VERSION < 0x050000 1469 1486 long dummyResult; 1470 1487 return m_views[m_iKeyboardHookViewIndex]->winEvent(&message, &dummyResult); 1488 #endif /* QT_VERSION < 0x050000 */ 1471 1489 } 1472 1490 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
r59361 r59372 1737 1737 bool UIMachineView::winEvent(MSG *pMsg, long* /* piResult */) 1738 1738 { 1739 /* Make sure arguments valid: */ 1739 1740 AssertPtrReturn(pMsg, false); 1740 1741 … … 1745 1746 switch (pMsg->message) 1746 1747 { 1748 /* Watch for key-events: */ 1747 1749 case WM_KEYDOWN: 1748 1750 case WM_KEYUP: … … 1751 1753 { 1752 1754 /* Can't do COM inter-process calls from a SendMessage handler, 1753 * see http://support.microsoft.com/kb/131056 */1755 * see http://support.microsoft.com/kb/131056. */ 1754 1756 if (vboxGlobal().isSeparateProcess() && InSendMessage()) 1755 1757 { … … 1769 1771 } 1770 1772 1773 /* Return result: */ 1771 1774 return fResult; 1772 1775 }
Note:
See TracChangeset
for help on using the changeset viewer.