Browse Source

+ add enhanced shift state to the TFPKeyEventRecord object and call
transEnhShiftState only in HandleKeyboard, when the new key event is added to
the queue. This way we can use GetKeyState to determine the parts of the shift
state that are not in dwControlKeyState.
* transEnhShiftState moved to be a local function inside HandleKeyboard to
ensure it's not called outside this procedure.

git-svn-id: branches/unicodekvm@40327 -

nickysn 6 years ago
parent
commit
baa6525a9e
1 changed files with 31 additions and 26 deletions
  1. 31 26
      packages/rtl-console/src/win/keyboard.pp

+ 31 - 26
packages/rtl-console/src/win/keyboard.pp

@@ -51,6 +51,7 @@ const MaxQueueSize = 120;
 type
 type
   TFPKeyEventRecord = record
   TFPKeyEventRecord = record
     ev: TKeyEventRecord;
     ev: TKeyEventRecord;
+    ShiftState: TEnhancedShiftState;
   end;
   end;
 var
 var
    keyboardeventqueue : array[0..maxqueuesize] of TFPKeyEventRecord;
    keyboardeventqueue : array[0..maxqueuesize] of TFPKeyEventRecord;
@@ -149,35 +150,36 @@ 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];
-  if ControlKeyState and NUMLOCK_ON <> 0 then
-    Include(b,essNumLockOn);
-  if ControlKeyState and CAPSLOCK_ON <> 0 then
-    Include(b,essCapsLockOn);
-  if ControlKeyState and SCROLLLOCK_ON <> 0 then
-    Include(b,essScrollLockOn);
-  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 }
 
 
 procedure HandleKeyboard(var ir:INPUT_RECORD);
 procedure HandleKeyboard(var ir:INPUT_RECORD);
+
+  { 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];
+    if ControlKeyState and NUMLOCK_ON <> 0 then
+      Include(b,essNumLockOn);
+    if ControlKeyState and CAPSLOCK_ON <> 0 then
+      Include(b,essCapsLockOn);
+    if ControlKeyState and SCROLLLOCK_ON <> 0 then
+      Include(b,essScrollLockOn);
+    transEnhShiftState := b;
+  end;
+
 var
 var
    i      : longint;
    i      : longint;
    c      : word;
    c      : word;
@@ -235,6 +237,8 @@ begin
                  begin
                  begin
                    keyboardeventqueue[nextfreekeyevent].ev:=
                    keyboardeventqueue[nextfreekeyevent].ev:=
                      ir.Event.KeyEvent;
                      ir.Event.KeyEvent;
+                   keyboardeventqueue[nextfreekeyevent].ShiftState:=
+                     transEnhShiftState(dwControlKeyState);
                    incqueueindex(nextfreekeyevent);
                    incqueueindex(nextfreekeyevent);
                  end;
                  end;
               end;
               end;
@@ -262,6 +266,7 @@ begin
                                                 {and add to queue}
                                                 {and add to queue}
                        EnterCriticalSection (lockVar);
                        EnterCriticalSection (lockVar);
                        keyboardeventqueue[nextfreekeyevent].ev:=ir.Event.KeyEvent;
                        keyboardeventqueue[nextfreekeyevent].ev:=ir.Event.KeyEvent;
+                       keyboardeventqueue[nextfreekeyevent].ShiftState:=transEnhShiftState(dwControlKeyState);
                        incqueueindex(nextfreekeyevent);
                        incqueueindex(nextfreekeyevent);
                        SetEvent (newKeyEvent);      {event that a new key is available}
                        SetEvent (newKeyEvent);      {event that a new key is available}
                        LeaveCriticalSection (lockVar);
                        LeaveCriticalSection (lockVar);
@@ -936,7 +941,7 @@ begin
       Key.UnicodeChar := t.ev.UnicodeChar;
       Key.UnicodeChar := t.ev.UnicodeChar;
       Key.AsciiChar := WideCharToOemCpChar(t.ev.UnicodeChar);
       Key.AsciiChar := WideCharToOemCpChar(t.ev.UnicodeChar);
       Key.VirtualScanCode := byte (Key.AsciiChar) + (t.ev.wVirtualScanCode shl 8);
       Key.VirtualScanCode := byte (Key.AsciiChar) + (t.ev.wVirtualScanCode shl 8);
-      ss := transEnhShiftState (t.ev.dwControlKeyState);
+      ss := t.ShiftState;
       Key.ShiftState := ss;
       Key.ShiftState := ss;
       if (essAlt in ss) and rightistruealt(t.ev.dwControlKeyState) then
       if (essAlt in ss) and rightistruealt(t.ev.dwControlKeyState) then
         Key.VirtualScanCode := Key.VirtualScanCode and $FF00;
         Key.VirtualScanCode := Key.VirtualScanCode and $FF00;
@@ -984,7 +989,7 @@ 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 := transEnhShiftState (t.ev.dwControlKeyState);
+    ss := t.ShiftState;
     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