From 467b293531b34ebf23162d10ee5a2d6ccfba0137 Mon Sep 17 00:00:00 2001 From: zeljko Date: Fri, 24 May 2013 07:20:39 +0000 Subject: [PATCH] Qt: fixed bug with AltGr key handling under windows.We are using winapi directly as workaround for bug in Qt library. issue #23808 git-svn-id: trunk@41378 - --- lcl/interfaces/qt/qtint.pp | 3 +++ lcl/interfaces/qt/qtobject.inc | 7 +++++++ lcl/interfaces/qt/qtwidgets.pas | 26 +++++++++++++++++++------- lcl/interfaces/qt/qtwinapi.inc | 13 +++++++++++-- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/lcl/interfaces/qt/qtint.pp b/lcl/interfaces/qt/qtint.pp index 2a2999d41d..593f2a107e 100644 --- a/lcl/interfaces/qt/qtint.pp +++ b/lcl/interfaces/qt/qtint.pp @@ -192,6 +192,9 @@ type FLastMinimizeEvent: DWord; // track mainform minimize events -> TQtMainWindow.EventFilter FMinimizedByPager: Boolean; // track if app is minimized via desktop pager or by us. {$ENDIF} + {$IFDEF MSWINDOWS} + function GetWinKeyState(AKeyState: LongInt): SHORT; + {$ENDIF} function CreateDefaultFont: HFONT; virtual; function GetDefaultAppFontName: WideString; function GetQtDefaultDC: HDC; virtual; diff --git a/lcl/interfaces/qt/qtobject.inc b/lcl/interfaces/qt/qtobject.inc index 6426aa379e..c982582306 100644 --- a/lcl/interfaces/qt/qtobject.inc +++ b/lcl/interfaces/qt/qtobject.inc @@ -1346,6 +1346,13 @@ begin QWidget_setVisible(FDragImageList, NewVisible); end; +{$IFDEF MSWINDOWS} +function TQtWidgetSet.GetWinKeyState(AKeyState: LongInt): SHORT; +begin + Result := Windows.GetKeyState(AKeyState); +end; +{$ENDIF} + {------------------------------------------------------------------------------ Function: CreateDefaultFont Params: none diff --git a/lcl/interfaces/qt/qtwidgets.pas b/lcl/interfaces/qt/qtwidgets.pas index 75bf535fdb..538ece4070 100644 --- a/lcl/interfaces/qt/qtwidgets.pas +++ b/lcl/interfaces/qt/qtwidgets.pas @@ -2799,15 +2799,27 @@ begin if QEvent_type(Event) = QEventKeyRelease then LCLModifiers := LCLModifiers or KF_UP; - KeyMsg.KeyData := PtrInt((AKeyCode shl 16) or (LCLModifiers shl 16) or $0001); - {$ifdef windows} - ACharCode := QKeyEvent_nativeVirtualKey(QKeyEventH(Event)); - KeyMsg.CharCode := ACharCode; - // todo: VK to Win_VK for other os too - //WriteLn(QKeyEvent_nativeVirtualKey(QKeyEventH(Event))); - //WriteLn(QKeyEvent_nativeScanCode(QKeyEventH(Event))); + ACharCode := QKeyEvent_nativeVirtualKey(QKeyEventH(Event)); + KeyMsg.CharCode := ACharCode; + if (Modifiers = QtAltModifier or QtControlModifier) then + begin + if (QtWidgetSet.GetWinKeyState(VK_RMENU) < 0) and + (QtWidgetSet.GetWinKeyState(VK_LCONTROL) < 0) then + begin + IsSysKey := False; + LCLModifiers := 0; + Modifiers := QtGroupSwitchModifier; + + if QKeyEvent_isAutoRepeat(QKeyEventH(Event)) then + LCLModifiers := LCLModifiers or KF_REPEAT; + + if QEvent_type(Event) = QEventKeyRelease then + LCLModifiers := LCLModifiers or KF_UP; + end; + end; {$endif} + KeyMsg.KeyData := PtrInt((AKeyCode shl 16) or (LCLModifiers shl 16) or $0001); // Loads the UTF-8 character associated with the keypress, if any QKeyEvent_text(QKeyEventH(Event), @Text); diff --git a/lcl/interfaces/qt/qtwinapi.inc b/lcl/interfaces/qt/qtwinapi.inc index 87d6b8cbcf..c86fc208fe 100644 --- a/lcl/interfaces/qt/qtwinapi.inc +++ b/lcl/interfaces/qt/qtwinapi.inc @@ -2975,6 +2975,16 @@ const begin Result := 0; + {$IFDEF MSWINDOWS} + if (nVirtKey = VK_CONTROL) or (nVirtKey = VK_MENU) or + (nVirtKey = VK_LCONTROL) or (nVirtKey = VK_LMENU) then + begin + if (GetWinKeyState(VK_RMENU) < 0) and + (GetWinKeyState(VK_LCONTROL) < 0) then + exit; + end; + {$ENDIF} + case nVirtKey of VK_LSHIFT: nVirtKey := VK_SHIFT; VK_LCONTROL: nVirtKey := VK_CONTROL; @@ -2982,7 +2992,6 @@ begin end; // where to track toggle state? - case nVirtKey of VK_LBUTTON: if (QApplication_mouseButtons and QtLeftButton) > 0 then @@ -3014,7 +3023,7 @@ begin VK_LCL_CAPSLOCK, VK_NUMLOCK: begin {$IFDEF MSWINDOWS} - Result := Windows.GetKeyState(nVirtKey); + Result := GetWinKeyState(nVirtKey); {$ELSE} {$IFDEF HASX11} if GetKeyLockState(nVirtKey) then