费了我很多工夫,你试试;代码是求鼠标在Button1上停留时间,Timer的InterVal为200: var bf: Boolean = true; s: TDateTime; st, et: LongWord;{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject); var mp: TPoint; ctl: TControl; begin GetCursorPos(mp); mp := ScreenToClient(mp); ctl := ControlAtPos(mp, true, true); if ctl <> nil then begin if ctl is TButton then begin if bf then begin st := GetTickCount; bf := false; s := Now(); end; Edit1.Text := FormatDateTime('ss:zzz秒', Now() - s); end; end else begin if not bf then et := GetTickCount; bf := true; Edit1.Text := FloatToStr((et - st)/1000) + ' 秒'; end; end;
软件控制鼠标按下左键5秒钟然后放开,怎么做?
http://expert.csdn.net/Expert/topic/2658/2658484.xml?temp=.8708155
var
bf: Boolean = true;
s: TDateTime;
st, et: LongWord;{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
var
mp: TPoint;
ctl: TControl;
begin
GetCursorPos(mp);
mp := ScreenToClient(mp);
ctl := ControlAtPos(mp, true, true);
if ctl <> nil then
begin
if ctl is TButton then
begin
if bf then
begin
st := GetTickCount;
bf := false;
s := Now();
end;
Edit1.Text := FormatDateTime('ss:zzz秒', Now() - s);
end;
end
else
begin
if not bf then et := GetTickCount;
bf := true;
Edit1.Text := FloatToStr((et - st)/1000) + ' 秒';
end;
end;