mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-20 10:09:17 +02:00
+ Added custom mouse driver example
This commit is contained in:
parent
393ef5c2c2
commit
4a60fc968b
@ -24,7 +24,7 @@
|
|||||||
% The Mouse unit
|
% The Mouse unit
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
\chapter{The MOUSE unit}
|
\chapter{The MOUSE unit}
|
||||||
\FPCexampledir{mousex}
|
\FPCexampledir{mouseex}
|
||||||
The \var{Mouse} unit implements a platform independent mouse handling
|
The \var{Mouse} unit implements a platform independent mouse handling
|
||||||
interface. It is implemented identically on all platforms supported by
|
interface. It is implemented identically on all platforms supported by
|
||||||
\fpc{} and can be enhanced with custom drivers, should this be needed.
|
\fpc{} and can be enhanced with custom drivers, should this be needed.
|
||||||
@ -333,3 +333,11 @@ For an example, see \seep{HideMouse}
|
|||||||
|
|
||||||
\section{Writing a custom mouse driver}
|
\section{Writing a custom mouse driver}
|
||||||
\label{se:mousedrv}
|
\label{se:mousedrv}
|
||||||
|
The \file{mouse} has support for adding a custom mouse driver. This can be
|
||||||
|
used to add support for mouses not supported by the standard \fpc{} driver,
|
||||||
|
but also to enhance an existing driver for instance to log mouse events or
|
||||||
|
to implement a record and playback function.
|
||||||
|
|
||||||
|
The following unit shows how a mouse driver can be enhanced by adding some
|
||||||
|
logging capabilities to the driver.
|
||||||
|
\FPCexample{logmouse}
|
||||||
|
@ -32,8 +32,9 @@ endif
|
|||||||
|
|
||||||
.PHONY: all tex clean
|
.PHONY: all tex clean
|
||||||
|
|
||||||
OBJECTS=mouse1 mouse2 mouse3 mouse4 mouse5 mouse6 mouse7 mouse8 mouse9 \
|
OBJECTS=ex1 ex2 ex3 ex4 ex5 ex6 ex7 logmouse
|
||||||
mouse10
|
# mouse8 mouse9 \
|
||||||
|
# mouse10
|
||||||
|
|
||||||
TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
|
TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
This directory contains the examples for the mouse unit.
|
This directory contains the examples for the mouse unit.
|
||||||
|
|
||||||
|
logmouse.pp contains and example of how to write a custom mouse driver.
|
||||||
|
|
||||||
ex1.pp contains an example of the DetectMouse function.
|
ex1.pp contains an example of the DetectMouse function.
|
||||||
ex2.pp contains an example of the GetMouseButtons function.
|
ex2.pp contains an example of the GetMouseButtons function.
|
||||||
ex3.pp contains an example of the GetMouseEvent function.
|
ex3.pp contains an example of the GetMouseEvent function.
|
||||||
|
116
docs/mouseex/logmouse.pp
Normal file
116
docs/mouseex/logmouse.pp
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
unit logmouse;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
Procedure StartMouseLogging;
|
||||||
|
Procedure StopMouseLogging;
|
||||||
|
Function IsMouseLogging : Boolean;
|
||||||
|
Procedure SetMouseLogFileName(FileName : String);
|
||||||
|
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
uses sysutils,Mouse;
|
||||||
|
|
||||||
|
var
|
||||||
|
NewMouseDriver,
|
||||||
|
OldMouseDriver : TMouseDriver;
|
||||||
|
Active,Logging : Boolean;
|
||||||
|
LogFileName : String;
|
||||||
|
MouseLog : Text;
|
||||||
|
|
||||||
|
Function TimeStamp : String;
|
||||||
|
|
||||||
|
begin
|
||||||
|
TimeStamp:=FormatDateTime('hh:nn:ss',Time());
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure StartMouseLogging;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Logging:=True;
|
||||||
|
Writeln(MouseLog,'Start logging mouse events at: ',TimeStamp);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure StopMouseLogging;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Writeln(MouseLog,'Stop logging mouse events at: ',TimeStamp);
|
||||||
|
Logging:=False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Function IsMouseLogging : Boolean;
|
||||||
|
|
||||||
|
begin
|
||||||
|
IsMouseLogging:=Logging;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure LogGetMouseEvent(Var Event : TMouseEvent);
|
||||||
|
|
||||||
|
Var
|
||||||
|
M : TMouseEvent;
|
||||||
|
|
||||||
|
begin
|
||||||
|
OldMouseDriver.GetMouseEvent(M);
|
||||||
|
If Logging then
|
||||||
|
begin
|
||||||
|
Write(MouseLog,TimeStamp,': Mouse ');
|
||||||
|
With M do
|
||||||
|
begin
|
||||||
|
Case Action of
|
||||||
|
MouseActionDown : Write(MouseLog,'down');
|
||||||
|
MouseActionUp : Write(MouseLog,'up');
|
||||||
|
MouseActionMove : Write(MouseLog,'move');
|
||||||
|
end;
|
||||||
|
Write(MouseLog,' event at ',X,',',Y);
|
||||||
|
If (Buttons<>0) then
|
||||||
|
begin
|
||||||
|
Write(MouseLog,' for buttons: ');
|
||||||
|
If (Buttons and MouseLeftbutton)<>0 then
|
||||||
|
Write(MouseLog,'Left ');
|
||||||
|
If (Buttons and MouseRightbutton)<>0 then
|
||||||
|
Write(MouseLog,'Right ');
|
||||||
|
If (Buttons and MouseMiddlebutton)<>0 then
|
||||||
|
Write(MouseLog,'Middle ');
|
||||||
|
end;
|
||||||
|
Writeln(MouseLog);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure LogInitMouse;
|
||||||
|
|
||||||
|
begin
|
||||||
|
OldMouseDriver.InitDriver();
|
||||||
|
Assign(MouseLog,logFileName);
|
||||||
|
Rewrite(MouseLog);
|
||||||
|
Active:=True;
|
||||||
|
StartMouseLogging;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure LogDoneMouse;
|
||||||
|
|
||||||
|
begin
|
||||||
|
StopMouseLogging;
|
||||||
|
Close(MouseLog);
|
||||||
|
Active:=False;
|
||||||
|
OldMouseDriver.DoneDriver();
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure SetMouseLogFileName(FileName : String);
|
||||||
|
|
||||||
|
begin
|
||||||
|
If Not Active then
|
||||||
|
LogFileName:=FileName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Initialization
|
||||||
|
GetMouseDriver(OldMouseDriver);
|
||||||
|
NewMouseDriver:=OldMouseDriver;
|
||||||
|
NewMouseDriver.GetMouseEvent:=@LogGetMouseEvent;
|
||||||
|
NewMouseDriver.InitDriver:=@LogInitMouse;
|
||||||
|
NewMouseDriver.DoneDriver:=@LogDoneMouse;
|
||||||
|
LogFileName:='Mouse.log';
|
||||||
|
Logging:=False;
|
||||||
|
SetMouseDriver(NewMouseDriver);
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user