+ Added demo for drivers and FunctionKeyName function

This commit is contained in:
michael 2001-10-03 21:36:58 +00:00
parent 20c39fbc19
commit db1b530e29
5 changed files with 156 additions and 3 deletions

View File

@ -32,8 +32,7 @@ endif
.PHONY: all tex clean
OBJECTS=ex1 ex2 ex3 ex4 ex5 ex6 ex7
# ex8 ex9 \
OBJECTS=ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9
# ex10 ex11 ex12 ex13 ex14 ex15 ex16 ex17 ex18
TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
@ -46,10 +45,16 @@ onetex : tex
$(MAKETEX) $(TEXOBJECTS)
clean :
rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS)
rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS) logkeys.ppu logkeys.o
rm -f keyboard.log
$(OBJECTS): %: %.pp
$(PP) $(PPOPTS) $*
$(TEXOBJECTS): %.tex: %.pp head.tex foot.tex
$(PP2TEX) $*
ex9: ex9.pp logkeys.ppu
logkeys.ppu: logkeys.pp
$(PP) $(PPOPTS) logkeys.pp

View File

@ -7,3 +7,6 @@ ex4.pp contains an example of the PollKeyEvent function.
ex5.pp contains an example of the PutKeyEvent function.
ex6.pp contains an example of the PollShiftStateEvent function.
ex7.pp contains an example of the IsFunctionKey function.
ex8.pp contains an example of the FunctionKeyName function.
logkeys.pp contains an example of a custom keyboard driver.
ex9.pp contains a demonstration program for the logkeys unit.

23
docs/kbdex/ex8.pp Normal file
View File

@ -0,0 +1,23 @@
Program Example8;
{ Program to demonstrate the FunctionKeyName function. }
Uses keyboard;
Var
K : TkeyEvent;
begin
InitKeyboard;
Writeln('Press function keys, press "q" to end.');
Repeat
K:=GetKeyEvent;
K:=TranslateKeyEvent(K);
If IsFunctionKey(k) then
begin
Write('Got function key : ');
Writeln(FunctionKeyName(TkeyRecord(K).KeyCode));
end;
Until (GetKeyEventChar(K)='q');
DoneKeyboard;
end.

24
docs/kbdex/ex9.pp Normal file
View File

@ -0,0 +1,24 @@
program example9;
{ This program demonstrates the logkeys unit }
uses keyboard,logkeys;
Var
K : TKeyEvent;
begin
InitKeyBoard;
Writeln('Press keys, press "q" to end, "s" toggles logging.');
Repeat
K:=GetKeyEvent;
K:=TranslateKeyEvent(K);
Writeln('Got key : ',KeyEventToString(K));
if GetKeyEventChar(K)='s' then
if IsKeyLogging then
StopKeyLogging
else
StartKeyLogging;
Until (GetKeyEventChar(K)='q');
DoneKeyBoard;
end.

98
docs/kbdex/logkeys.pp Normal file
View File

@ -0,0 +1,98 @@
unit logkeys;
interface
Procedure StartKeyLogging;
Procedure StopKeyLogging;
Function IsKeyLogging : Boolean;
Procedure SetKeyLogFileName(FileName : String);
implementation
uses sysutils,keyboard;
var
NewKeyBoardDriver,
OldKeyBoardDriver : TKeyboardDriver;
Active,Logging : Boolean;
LogFileName : String;
KeyLog : Text;
Function TimeStamp : String;
begin
TimeStamp:=FormatDateTime('hh:nn:ss',Time());
end;
Procedure StartKeyLogging;
begin
Logging:=True;
Writeln(KeyLog,'Start logging keystrokes at: ',TimeStamp);
end;
Procedure StopKeyLogging;
begin
Writeln(KeyLog,'Stop logging keystrokes at: ',TimeStamp);
Logging:=False;
end;
Function IsKeyLogging : Boolean;
begin
IsKeyLogging:=Logging;
end;
Function LogGetKeyEvent : TKeyEvent;
Var
K : TKeyEvent;
begin
K:=OldkeyboardDriver.GetKeyEvent();
If Logging then
begin
Write(KeyLog,TimeStamp);
Writeln(KeyLog,': Key event: ',KeyEventToString(TranslateKeyEvent(K)));
end;
LogGetKeyEvent:=K;
end;
Procedure LogInitKeyBoard;
begin
OldKeyBoardDriver.InitDriver();
Assign(KeyLog,logFileName);
Rewrite(KeyLog);
Active:=True;
StartKeyLogging;
end;
Procedure LogDoneKeyBoard;
begin
StopKeyLogging;
Close(KeyLog);
Active:=False;
OldKeyBoardDriver.DoneDriver();
end;
Procedure SetKeyLogFileName(FileName : String);
begin
If Not Active then
LogFileName:=FileName;
end;
Initialization
GetKeyBoardDriver(OldKeyBoardDriver);
NewKeyBoardDriver:=OldKeyBoardDriver;
NewKeyBoardDriver.GetKeyEvent:=@LogGetKeyEvent;
NewKeyBoardDriver.InitDriver:=@LogInitKeyboard;
NewKeyBoardDriver.DoneDriver:=@LogDoneKeyboard;
LogFileName:='keyboard.log';
Logging:=False;
SetKeyboardDriver(NewKeyBoardDriver);
end.