Browse Source

* finished

Tomas Hajny 25 years ago
parent
commit
858c472369
1 changed files with 67 additions and 7 deletions
  1. 67 7
      api/os2/keyboard.inc

+ 67 - 7
api/os2/keyboard.inc

@@ -20,16 +20,21 @@ uses
  {$ENDIF} 
  {$ENDIF} 
 {$ENDIF}
 {$ENDIF}
 
 
-type
 {$IFDEF PPC_VIRTUAL}
 {$IFDEF PPC_VIRTUAL}
+type
  TKbdKeyInfo = KbdKeyInfo;
  TKbdKeyInfo = KbdKeyInfo;
  TKbdInfo = KbdInfo;
  TKbdInfo = KbdInfo;
 {$ELSE}
 {$ELSE}
  {$IFDEF PPC_SPEED}
  {$IFDEF PPC_SPEED}
+type
  TKbdKeyInfo = KbdKeyInfo;
  TKbdKeyInfo = KbdKeyInfo;
  TKbdInfo = KbdInfo;
  TKbdInfo = KbdInfo;
  {$ENDIF}
  {$ENDIF}
 {$ENDIF}
 {$ENDIF}
+{$IFNDEF PPC_FPC}
+type
+ cardinal = longint;
+{$ENDIF}
 
 
 const
 const
  DefaultKeyboard = 0;
  DefaultKeyboard = 0;
@@ -66,7 +71,6 @@ end;
 function GetKeyEvent: TKeyEvent;
 function GetKeyEvent: TKeyEvent;
 var
 var
  K: TKbdKeyInfo;
  K: TKbdKeyInfo;
- RC: word;
 begin
 begin
  if PendingKeyEvent <> 0 then
  if PendingKeyEvent <> 0 then
  begin
  begin
@@ -77,7 +81,7 @@ begin
   KbdGetFocus (IO_Wait, Handle);
   KbdGetFocus (IO_Wait, Handle);
   while (KbdCharIn (K, IO_Wait, Handle) <> No_Error)
   while (KbdCharIn (K, IO_Wait, Handle) <> No_Error)
                                    or (K.fbStatus and $40 = 0) do DosSleep (5);
                                    or (K.fbStatus and $40 = 0) do DosSleep (5);
-  with K do GetKeyEvent := cardinal (fsState or $F) shl 16 or
+  with K do GetKeyEvent := cardinal ($0300 or fsState and $F) shl 16 or
                                cardinal (byte (chScan)) shl 8 or byte (chChar);
                                cardinal (byte (chScan)) shl 8 or byte (chChar);
  end;
  end;
 end;
 end;
@@ -89,9 +93,9 @@ begin
  if PendingKeyEvent = 0 then
  if PendingKeyEvent = 0 then
  begin
  begin
   KbdGetFocus (IO_NoWait, Handle);
   KbdGetFocus (IO_NoWait, Handle);
-  if (KbdCharIn (K, IO_NoWait, Handle) <> NoError) or
-       (K.fbStatus and $40 = 0) then FillChar (K, SizeOf (K), 0) else
-            with K do PendingKeyEvent := cardinal (fsState or $F) shl 16 or
+  if (KbdCharIn (K, IO_NoWait, Handle) <> No_Error) or
+   (K.fbStatus and $40 = 0) then FillChar (K, SizeOf (K), 0) else
+     with K do PendingKeyEvent := cardinal ($0300 or fsState and $F) shl 16 or
                                cardinal (byte (chScan)) shl 8 or byte (chChar);
                                cardinal (byte (chScan)) shl 8 or byte (chChar);
  end;
  end;
  PollKeyEvent := PendingKeyEvent;
  PollKeyEvent := PendingKeyEvent;
@@ -99,20 +103,76 @@ begin
 end;
 end;
 
 
 function PollShiftStateEvent: TKeyEvent;
 function PollShiftStateEvent: TKeyEvent;
+var
+ K: TKbdInfo;
 begin
 begin
+ KbdGetFocus (IO_NoWait, Handle);
+ KbdGetStatus (K, Handle);
+ PollShiftStateEvent := cardinal (K.fsState and $F) shl 16;
 end;
 end;
 
 
+type
+{$IFDEF PPC_FPC}
+ TTranslationEntry = packed record
+{$ELSE}
+ TTranslationEntry = record
+{$ENDIF}
+  Min, Max: byte;
+  Offset: word;
+ end;
+
+const
+ TranslationTableEntries = 12;
+ TranslationTable: array [1..TranslationTableEntries] of TTranslationEntry =
+    ((Min: $3B; Max: $44; Offset: kbdF1),   { function keys F1-F10 }
+     (Min: $54; Max: $5D; Offset: kbdF1),   { Shift fn keys F1-F10 }
+     (Min: $5E; Max: $67; Offset: kbdF1),   { Ctrl fn keys F1-F10 }
+     (Min: $68; Max: $71; Offset: kbdF1),   { Alt fn keys F1-F10 }
+     (Min: $85; Max: $86; Offset: kbdF11),  { function keys F11-F12 }
+     (Min: $87; Max: $88; Offset: kbdF11),  { Shift+function keys F11-F12 }
+     (Min: $89; Max: $8A; Offset: kbdF11),  { Ctrl+function keys F11-F12 }
+     (Min: $8B; Max: $8C; Offset: kbdF11),  { Alt+function keys F11-F12 }
+     (Min:  71; Max:  73; Offset: kbdHome), { Keypad keys kbdHome-kbdPgUp }
+     (Min:  75; Max:  77; Offset: kbdLeft), { Keypad keys kbdLeft-kbdRight }
+     (Min:  79; Max:  81; Offset: kbdEnd),  { Keypad keys kbdEnd-kbdPgDn }
+     (Min: $52; Max: $53; Offset: kbdInsert));
+
+
 function TranslateKeyEvent (KeyEvent: TKeyEvent): TKeyEvent;
 function TranslateKeyEvent (KeyEvent: TKeyEvent): TKeyEvent;
+var
+ I: integer;
+ ScanCode: byte;
 begin
 begin
+ if KeyEvent and $03000000 = $03000000 then
+ begin
+  if (KeyEvent and $000000FF <> 0) and (KeyEvent and $000000FF <> $E0) then
+                               TranslateKeyEvent := KeyEvent and $00FFFFFF else
+  begin
+{ This is a function key }
+   ScanCode := (KeyEvent and $0000FF00) shr 8;
+   I := 1;
+   while (I <= TranslationTableEntries) and
+       ((TranslationTable [I].Min > ScanCode) or
+                             (ScanCode > TranslationTable [I].Max)) do Inc (I);
+   if I > TranslationTableEntries then TranslateKeyEvent := KeyEvent else
+           TranslateKeyEvent := $02000000 + (KeyEvent and $00FF0000) +
+             (ScanCode - TranslationTable[I].Min) + TranslationTable[I].Offset;
+  end;
+ end else TranslateKeyEvent := KeyEvent;
 end;
 end;
 
 
 function TranslateKeyEventUniCode (KeyEvent: TKeyEvent): TKeyEvent;
 function TranslateKeyEventUniCode (KeyEvent: TKeyEvent): TKeyEvent;
 begin
 begin
+ TranslateKeyEventUniCode := KeyEvent;
+ ErrorHandler (errKbdNotImplemented, nil);
 end;
 end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.3  2000-03-19 11:29:07  hajny
+  Revision 1.4  2000-04-08 19:54:26  hajny
+    * finished
+
+  Revision 1.3  2000/03/19 11:29:07  hajny
     * PollKeyEvent implemented
     * PollKeyEvent implemented
 
 
   Revision 1.2  2000/01/09 20:42:05  hajny
   Revision 1.2  2000/01/09 20:42:05  hajny