放个Timer控件,然后:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
procedure FormKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MouseHide: Boolean;
implementation
{$R *.DFM}
procedure DoMouse;
begin
if MouseHide then
begin
Screen.Cursor:=crDefault; { 恢复鼠标 }
MouseHide:=False;
end
else Form1.Timer1.Enabled:=True;
end;
procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DoMouse;
end;
procedure TForm1.FormMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
DoMouse;
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
DoMouse;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MouseHide:=True; { 初始化 }
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
MouseHide:=True;
Screen.Cursor:=crNone; { 隐藏鼠标 }
{ 以下这一行可以不要,但会使程序效率降低 }
Timer1.Enabled:=False;
end;
end.