Browse Source

* TEnhancedKeyEvent.ShiftState changed to TEnhancedShiftState

git-svn-id: branches/unicodekvm@40311 -
nickysn 6 years ago
parent
commit
4f482516dd

+ 38 - 2
packages/rtl-console/src/inc/keyboard.inc

@@ -108,6 +108,28 @@ begin
 end;
 end;
 
 
 
 
+function ConvertEnhancedToLegacyShiftState(const ShiftState: TEnhancedShiftState): Byte;
+begin
+  ConvertEnhancedToLegacyShiftState:=0;
+  if essAlt in ShiftState then
+    ConvertEnhancedToLegacyShiftState:=ConvertEnhancedToLegacyShiftState or kbAlt;
+  if essCtrl in ShiftState then
+    ConvertEnhancedToLegacyShiftState:=ConvertEnhancedToLegacyShiftState or kbCtrl;
+  if essShift in ShiftState then
+    begin
+      if ([essLeftShift,essRightShift]*ShiftState)=[] then
+        ConvertEnhancedToLegacyShiftState:=ConvertEnhancedToLegacyShiftState or kbShift
+      else
+        begin
+          if essLeftShift in ShiftState then
+            ConvertEnhancedToLegacyShiftState:=ConvertEnhancedToLegacyShiftState or kbLeftShift;
+          if essRightShift in ShiftState then
+            ConvertEnhancedToLegacyShiftState:=ConvertEnhancedToLegacyShiftState or kbRightShift;
+        end;
+    end;
+end;
+
+
 function ConvertToLegacyKeyEvent(const KeyEvent: TEnhancedKeyEvent): TKeyEvent;
 function ConvertToLegacyKeyEvent(const KeyEvent: TEnhancedKeyEvent): TKeyEvent;
 begin
 begin
   if KeyEvent=NilEnhancedKeyEvent then
   if KeyEvent=NilEnhancedKeyEvent then
@@ -115,7 +137,7 @@ begin
   else
   else
     ConvertToLegacyKeyEvent:=(kbPhys shl 24) or
     ConvertToLegacyKeyEvent:=(kbPhys shl 24) or
       ConvertExtendedToStandardScanCode(KeyEvent.VirtualScanCode) or
       ConvertExtendedToStandardScanCode(KeyEvent.VirtualScanCode) or
-      (KeyEvent.ShiftState shl 16);
+      (ConvertEnhancedToLegacyShiftState(KeyEvent.ShiftState) shl 16);
 end;
 end;
 
 
 
 
@@ -198,11 +220,25 @@ end;
 function ConvertToEnhancedKeyEvent(KeyEvent: TKeyEvent): TEnhancedKeyEvent;
 function ConvertToEnhancedKeyEvent(KeyEvent: TKeyEvent): TEnhancedKeyEvent;
 var
 var
   TranslatedKeyEvent: TKeyEvent;
   TranslatedKeyEvent: TKeyEvent;
+  ShiftState: Byte;
 begin
 begin
   ConvertToEnhancedKeyEvent:=NilEnhancedKeyEvent;
   ConvertToEnhancedKeyEvent:=NilEnhancedKeyEvent;
   if KeyEvent=0 then
   if KeyEvent=0 then
     exit;
     exit;
-  ConvertToEnhancedKeyEvent.ShiftState:=GetKeyEventShiftState(KeyEvent);
+  ConvertToEnhancedKeyEvent.ShiftState:=[];
+  ShiftState:=GetKeyEventShiftState(KeyEvent);
+  if (kbAlt and ShiftState)<>0 then
+    Include(ConvertToEnhancedKeyEvent.ShiftState,essAlt);
+  if (kbCtrl and ShiftState)<>0 then
+    Include(ConvertToEnhancedKeyEvent.ShiftState,essCtrl);
+  if (kbShift and ShiftState)<>0 then
+    begin
+      Include(ConvertToEnhancedKeyEvent.ShiftState,essShift);
+      if (kbLeftShift and ShiftState)<>0 then
+        Include(ConvertToEnhancedKeyEvent.ShiftState,essLeftShift);
+      if (kbRightShift and ShiftState)<>0 then
+        Include(ConvertToEnhancedKeyEvent.ShiftState,essRightShift);
+    end;
   case GetKeyEventFlags(KeyEvent) of
   case GetKeyEventFlags(KeyEvent) of
     kbASCII:
     kbASCII:
       ConvertToEnhancedKeyEvent.AsciiChar:=GetKeyEventChar(KeyEvent);
       ConvertToEnhancedKeyEvent.AsciiChar:=GetKeyEventChar(KeyEvent);

+ 3 - 2
packages/rtl-console/src/inc/keybrdh.inc

@@ -77,7 +77,8 @@ type
     VirtualScanCode: Word;   { device-dependent value, generated by the keyboard }
     VirtualScanCode: Word;   { device-dependent value, generated by the keyboard }
     UnicodeChar: WideChar;   { the translated Unicode character }
     UnicodeChar: WideChar;   { the translated Unicode character }
     AsciiChar: Char;         { the translated ASCII character }
     AsciiChar: Char;         { the translated ASCII character }
-    ShiftState, Flags: Byte;
+    ShiftState: TEnhancedShiftState;
+    Flags: Byte;
   end;
   end;
 
 
 const
 const
@@ -87,7 +88,7 @@ const
     VirtualScanCode: 0;
     VirtualScanCode: 0;
     UnicodeChar: #0;
     UnicodeChar: #0;
     AsciiChar: #0;
     AsciiChar: #0;
-    ShiftState: 0;
+    ShiftState: [];
     Flags: 0;
     Flags: 0;
   );
   );
 { System independent function key codes }
 { System independent function key codes }

+ 30 - 11
packages/rtl-console/src/win/keyboard.pp

@@ -145,6 +145,25 @@ begin
   transShiftState := b;
   transShiftState := b;
 end;
 end;
 
 
+{ translate win32 shift-state to keyboard shift state }
+function transEnhShiftState (ControlKeyState : dword) : TEnhancedShiftState;
+var b : TEnhancedShiftState;
+begin
+  b := [];
+  if ControlKeyState and SHIFT_PRESSED <> 0 then  { win32 makes no difference between left and right shift }
+    Include(b,essShift);
+  if ControlKeyState and LEFT_CTRL_PRESSED <> 0 then
+    b:=b+[essCtrl,essLeftCtrl];
+  if ControlKeyState and RIGHT_CTRL_PRESSED <> 0 then
+    b:=b+[essCtrl,essRightCtrl];
+  if ControlKeyState and LEFT_ALT_PRESSED <> 0 then
+    b:=b+[essAlt,essLeftAlt];
+  if ControlKeyState and RIGHT_ALT_PRESSED <> 0 then
+    b:=b+[essAlt,essRightAlt];
+  transEnhShiftState := b;
+end;
+
+
 { The event-Handler thread from the unit event will call us if a key-event
 { The event-Handler thread from the unit event will call us if a key-event
   is available }
   is available }
 
 
@@ -878,7 +897,7 @@ end;
 
 
 function TranslateEnhancedKeyEvent (t : TKeyEventRecord) : TEnhancedKeyEvent;
 function TranslateEnhancedKeyEvent (t : TKeyEventRecord) : TEnhancedKeyEvent;
 var key : TEnhancedKeyEvent;
 var key : TEnhancedKeyEvent;
-    ss  : byte;
+    ss  : TEnhancedShiftState;
 {$ifdef  USEKEYCODES}
 {$ifdef  USEKEYCODES}
     ScanCode  : byte;
     ScanCode  : byte;
 {$endif  USEKEYCODES}
 {$endif  USEKEYCODES}
@@ -907,9 +926,9 @@ begin
       Key.UnicodeChar := t.UnicodeChar;
       Key.UnicodeChar := t.UnicodeChar;
       Key.AsciiChar := WideCharToOemCpChar(t.UnicodeChar);
       Key.AsciiChar := WideCharToOemCpChar(t.UnicodeChar);
       Key.VirtualScanCode := byte (Key.AsciiChar) + (t.wVirtualScanCode shl 8);
       Key.VirtualScanCode := byte (Key.AsciiChar) + (t.wVirtualScanCode shl 8);
-      ss := transShiftState (t.dwControlKeyState);
+      ss := transEnhShiftState (t.dwControlKeyState);
       Key.ShiftState := ss;
       Key.ShiftState := ss;
-      if (ss and kbAlt <> 0) and rightistruealt(t.dwControlKeyState) then
+      if (essAlt in ss) and rightistruealt(t.dwControlKeyState) then
         Key.VirtualScanCode := Key.VirtualScanCode and $FF00;
         Key.VirtualScanCode := Key.VirtualScanCode and $FF00;
 {$else not USEKEYCODES}
 {$else not USEKEYCODES}
       Key.UnicodeChar := t.UnicodeChar;
       Key.UnicodeChar := t.UnicodeChar;
@@ -955,13 +974,13 @@ begin
       Key.VirtualScanCode := (Key.VirtualScanCode and $ff00) or ord('~');
       Key.VirtualScanCode := (Key.VirtualScanCode and $ff00) or ord('~');
     end;
     end;
     { ok, now add Shift-State }
     { ok, now add Shift-State }
-    ss := transShiftState (t.dwControlKeyState);
+    ss := transEnhShiftState (t.dwControlKeyState);
     Key.ShiftState := ss;
     Key.ShiftState := ss;
 
 
     { Reset Ascii-Char if Alt+Key, fv needs that, may be we
     { Reset Ascii-Char if Alt+Key, fv needs that, may be we
       need it for other special keys too
       need it for other special keys too
       18 Sept 1999 AD: not for right Alt i.e. for AltGr+ß = \ on german keyboard }
       18 Sept 1999 AD: not for right Alt i.e. for AltGr+ß = \ on german keyboard }
-    if ((ss and kbAlt <> 0) and rightistruealt(t.dwControlKeyState)) or
+    if (essAlt in ss) and rightistruealt(t.dwControlKeyState) or
     (*
     (*
       { yes, we need it for cursor keys, 25=left, 26=up, 27=right,28=down}
       { yes, we need it for cursor keys, 25=left, 26=up, 27=right,28=down}
       {aggg, this will not work because esc is also virtualKeyCode 27!!}
       {aggg, this will not work because esc is also virtualKeyCode 27!!}
@@ -982,13 +1001,13 @@ begin
         (t.wVirtualScanCode <= high (dosTT)) then
         (t.wVirtualScanCode <= high (dosTT)) then
      begin
      begin
        b := 0;
        b := 0;
-       if (ss and kbAlt) <> 0 then
+       if essAlt in ss then
          b := DosTT[t.wVirtualScanCode].a
          b := DosTT[t.wVirtualScanCode].a
        else
        else
-       if (ss and kbCtrl) <> 0 then
+       if essCtrl in ss then
          b := DosTT[t.wVirtualScanCode].c
          b := DosTT[t.wVirtualScanCode].c
        else
        else
-       if (ss and kbShift) <> 0 then
+       if essShift in ss then
          b := DosTT[t.wVirtualScanCode].s
          b := DosTT[t.wVirtualScanCode].s
        else
        else
          b := DosTT[t.wVirtualScanCode].n;
          b := DosTT[t.wVirtualScanCode].n;
@@ -1002,13 +1021,13 @@ begin
           (t.wVirtualScanCode <= high (dosTT09)) then
           (t.wVirtualScanCode <= high (dosTT09)) then
        begin
        begin
          b := 0;
          b := 0;
-         if (ss and kbAlt) <> 0 then
+         if essAlt in ss then
            b := DosTT09[t.wVirtualScanCode].a
            b := DosTT09[t.wVirtualScanCode].a
          else
          else
-         if (ss and kbCtrl) <> 0 then
+         if essCtrl in ss then
            b := DosTT09[t.wVirtualScanCode].c
            b := DosTT09[t.wVirtualScanCode].c
          else
          else
-         if (ss and kbShift) <> 0 then
+         if essShift in ss then
            b := DosTT09[t.wVirtualScanCode].s
            b := DosTT09[t.wVirtualScanCode].s
          else
          else
            b := DosTT09[t.wVirtualScanCode].n;
            b := DosTT09[t.wVirtualScanCode].n;