+ added unit System.Terminal.KeyboardInput.Keyboard

This commit is contained in:
Nikolay Nikolov 2024-10-20 14:14:52 +03:00
parent 481ef7273e
commit eb29d4fa95
2 changed files with 183 additions and 0 deletions

View File

@ -7,6 +7,27 @@ uses {$ifdef unix}cthreads,{$endif} fpmkunit;
procedure add_fcl_fpterm(const ADirectory: string);
Const
{copied from ../rtl-console/fpmake.pp}
// All Unices have full set of KVM+Crt in unix/ except QNX which is not
// in workable state atm.
UnixLikes = AllUnixOSes -[QNX];
WinEventOSes = [win32,win64];
KVMAll = [emx,go32v2,msdos,netware,netwlibc,os2,win32,win64,win16]+UnixLikes+AllAmigaLikeOSes;
// all full KVMers have crt too
CrtOSes = KVMALL+[WatCom];
KbdOSes = KVMALL;
VideoOSes = KVMALL;
MouseOSes = KVMALL;
TerminfoOSes = UnixLikes-[beos,haiku];
rtl_consoleOSes =KVMALL+CrtOSes+TermInfoOSes;
{end of copied code}
KVMAny = KbdOSes+VideoOSes+MouseOSes;
Var
P : TPackage;
T : TTarget;
@ -27,6 +48,8 @@ begin
P.SourcePath.Add('src');
p.Dependencies.Add('rtl-console', KVMAny);
T:=P.Targets.AddUnit('system.terminal.base.pas');
T:=P.Targets.AddUnit('system.terminal.view.pas');
@ -78,6 +101,13 @@ begin
AddUnit('system.terminal.keyboardinput');
end;
T:=P.Targets.AddUnit('system.terminal.keyboardinput.keyboard.pas', KbdOSes);
with T.Dependencies do
begin
AddUnit('system.terminal.base');
AddUnit('system.terminal.keyboardinput');
end;
//P.NamespaceMap:='namespaces.lst';
end;
end;

View File

@ -0,0 +1,153 @@
{ This file is part of fpterm - a terminal emulator, written in Free Pascal
This unit implements a keyboard for the terminal, using unit 'keyboard'.
Copyright (C) 2024 Nikolay Nikolov <nickysn@users.sourceforge.net>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,and
to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a
module which is not derived from or based on this library. If you modify
this library, you may extend this exception to your version of the library,
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.
}
unit System.Terminal.KeyboardInput.Keyboard;
{$mode objfpc}{$H+}
interface
uses
System.Terminal.Base, System.Terminal.KeyboardInput;
type
{ TTerminalKeyboardInput_Keyboard }
TTerminalKeyboardInput_Keyboard = class(TTerminalKeyboardInput)
protected
function IsEventAvailable: Boolean; override;
public
constructor Create; override;
destructor Destroy; override;
procedure GetEvent(out Event: System.Terminal.Base.TKeyEvent); override;
end;
implementation
uses
{$IFDEF FPC_DOTTEDUNITS}
System.Console.Keyboard;
{$ELSE FPC_DOTTEDUNITS}
Keyboard;
{$ENDIF FPC_DOTTEDUNITS}
{$IFDEF FPC_DOTTEDUNITS}
function ConvertShiftState(ess: System.Console.Keyboard.TEnhancedShiftState): System.Terminal.Base.TShiftState;
{$ELSE FPC_DOTTEDUNITS}
function ConvertShiftState(ess: Keyboard.TEnhancedShiftState): System.Terminal.Base.TShiftState;
{$ENDIF FPC_DOTTEDUNITS}
begin
Result := [];
if essShift in ess then
Include(Result, ssShift);
if essLeftShift in ess then
Include(Result, ssLeftShift);
if essRightShift in ess then
Include(Result, ssRightShift);
if essCtrl in ess then
Include(Result, ssCtrl);
if essLeftCtrl in ess then
Include(Result, ssLeftCtrl);
if essRightCtrl in ess then
Include(Result, ssRightCtrl);
if essAlt in ess then
Include(Result, ssAlt);
if essLeftAlt in ess then
Include(Result, ssLeftAlt);
if essRightAlt in ess then
Include(Result, ssRightAlt);
if essAltGr in ess then
Include(Result, ssAltGr);
if essCapsLockPressed in ess then
Include(Result, ssCapsLockPressed);
if essCapsLockOn in ess then
Include(Result, ssCapsLockOn);
if essNumLockPressed in ess then
Include(Result, ssNumLockPressed);
if essNumLockOn in ess then
Include(Result, ssNumLockOn);
if essScrollLockPressed in ess then
Include(Result, ssScrollLockPressed);
if essScrollLockOn in ess then
Include(Result, ssScrollLockOn);
end;
{$IFDEF FPC_DOTTEDUNITS}
procedure EnhancedKeyEvent2TerminalKeyEvent(const k: System.Console.Keyboard.TEnhancedKeyEvent; var tk: System.Terminal.Base.TKeyEvent);
{$ELSE FPC_DOTTEDUNITS}
procedure EnhancedKeyEvent2TerminalKeyEvent(const k: Keyboard.TEnhancedKeyEvent; var tk: System.Terminal.Base.TKeyEvent);
{$ENDIF FPC_DOTTEDUNITS}
begin
tk.VirtualKeyCode := k.VirtualKeyCode;
tk.VirtualScanCode := k.VirtualScanCode;
tk.UnicodeChar := k.UnicodeChar;
tk.AsciiChar := k.AsciiChar;
tk.ShiftState := ConvertShiftState(k.ShiftState);
tk.Flags := k.Flags;
end;
{ TTerminalKeyboardInput_Keyboard }
function TTerminalKeyboardInput_Keyboard.IsEventAvailable: Boolean;
begin
Result := PollEnhancedKeyEvent <> NilEnhancedKeyEvent;
end;
constructor TTerminalKeyboardInput_Keyboard.Create;
begin
inherited Create;
InitKeyboard;
end;
destructor TTerminalKeyboardInput_Keyboard.Destroy;
begin
DoneKeyboard;
inherited Destroy;
end;
procedure TTerminalKeyboardInput_Keyboard.GetEvent(out Event: System.Terminal.Base.TKeyEvent);
var
{$IFDEF FPC_DOTTEDUNITS}
k: System.Console.Keyboard.TEnhancedKeyEvent;
{$ELSE FPC_DOTTEDUNITS}
k: Keyboard.TEnhancedKeyEvent;
{$ENDIF FPC_DOTTEDUNITS}
begin
FillChar(Event, SizeOf(Event), 0);
k := GetEnhancedKeyEvent;
EnhancedKeyEvent2TerminalKeyEvent(k, Event);
end;
end.