Delphi程序自动退出

Freeid_shi 2010-01-08 09:55:48
我有一个Delphi+SQL的程序,运行后我希望能做检测用户有没有在操作?
如果一段时间没有操作这个程序就自动退出。
目前想的是放一个计时器,设置一个时间,到了就关闭程序。
现在不知道如何判断操作员有没有操作动作?
哪位教一下,多谢!
...全文
569 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hjkto 2010-01-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 heikeyanxi 的回复:]
完整代码:
Delphi(Pascal) codefunction StopTime: integer;//返回没有键盘和鼠标事件的时间var
LInput: TLastInputInfo;begin
LInput.cbSize := SizeOf(TLastInputInfo);
GetLastInputInfo(LInput);
Result := (GetTickCount()- LInput.dwTime)div1000;// 微妙换成秒end;procedure TForm1.Timer1Timer(Sender: TObject);// Timer 事件beginif StopTime>=60then
Showmessage('用户已经1分钟没有动键盘鼠标了!');end;

只要用户动了鼠标或键盘,计数就会重新开始,GetLastInputInfo是核心
[/Quote]
不错,虽然有了
梦幻人生 2010-01-09
  • 打赏
  • 举报
回复
學習!
yanele 2010-01-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 heikeyanxi 的回复:]
完整代码:
Delphi(Pascal) codefunction StopTime: integer;//返回没有键盘和鼠标事件的时间var
LInput: TLastInputInfo;begin
LInput.cbSize := SizeOf(TLastInputInfo);
GetLastInputInfo(LInput);
Result := (GetTickCount()- LInput.dwTime)div1000;// 微妙换成秒end;
只要用户动了鼠标或键盘,计数就会重新开始,GetLastInputInfo是核心
[/Quote]

正需要,学习收藏!
huangheguyun 2010-01-09
  • 打赏
  • 举报
回复
学习
kobaer 2010-01-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 heikeyanxi 的回复:]
完整代码:
Delphi(Pascal) codefunction StopTime: integer;//返回没有键盘和鼠标事件的时间var
LInput: TLastInputInfo;begin
LInput.cbSize := SizeOf(TLastInputInfo);
GetLastInputInfo(LInput);
Result := (GetTickCount()- LInput.dwTime)div1000;// 微妙换成秒end;procedure TForm1.Timer1Timer(Sender: TObject);// Timer 事件beginif StopTime>=60then
Showmessage('用户已经1分钟没有动键盘鼠标了!');end;

只要用户动了鼠标或键盘,计数就会重新开始,GetLastInputInfo是核心
[/Quote]


呵呵 3Q
sachuangwei_boy 2010-01-08
  • 打赏
  • 举报
回复
学习
heikeyanxi 2010-01-08
  • 打赏
  • 举报
回复
完整代码:

function StopTime: integer; //返回没有键盘和鼠标事件的时间
var
LInput: TLastInputInfo;
begin
LInput.cbSize := SizeOf(TLastInputInfo);
GetLastInputInfo(LInput);
Result := (GetTickCount() - LInput.dwTime) div 1000; // 微妙换成秒
end;

procedure TForm1.Timer1Timer(Sender: TObject); // Timer 事件
begin
if StopTime >= 60 then
Showmessage('用户已经1分钟没有动键盘鼠标了!');
end;


只要用户动了鼠标或键盘,计数就会重新开始,GetLastInputInfo是核心
Freeid_shi 2010-01-08
  • 打赏
  • 举报
回复
这是一个方法,还有没有更直接的
如果在操作计算机,没有在程序里有动作的情况。
idecl 2010-01-08
  • 打赏
  • 举报
回复
用一个TIMER设一个时间,到了时间就退出
当有鼠标或者键盘操作时,TIMER重新计时就行了
winstonbonaparte 2010-01-08
  • 打赏
  • 举报
回复
判断鼠标或是键盘长时间没有操作,就象屏保一样
Bear_hx 2010-01-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 heikeyanxi 的回复:]
完整代码:
Delphi(Pascal) codefunction StopTime: integer;//返回没有键盘和鼠标事件的时间var
LInput: TLastInputInfo;begin
LInput.cbSize := SizeOf(TLastInputInfo);
GetLastInputInfo(LInput);
Result := (GetTickCount()- LInput.dwTime)div1000;// 微妙换成秒end;procedure TForm1.Timer1Timer(Sender: TObject);// Timer 事件beginif StopTime>=60then
Showmessage('用户已经1分钟没有动键盘鼠标了!');end;

只要用户动了鼠标或键盘,计数就会重新开始,GetLastInputInfo是核心
[/Quote]
这个是解决办法,也可以用HOOK来做到
haochin 2010-01-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 heikeyanxi 的回复:]
完整代码:
Delphi(Pascal) codefunction StopTime: integer;//返回没有键盘和鼠标事件的时间var
LInput: TLastInputInfo;begin
LInput.cbSize := SizeOf(TLastInputInfo);
GetLastInputInfo(LInput);
Result := (GetTickCount()- LInput.dwTime)div1000;// 微妙换成秒end;procedure TForm1.Timer1Timer(Sender: TObject);// Timer 事件beginif StopTime>=60then
Showmessage('用户已经1分钟没有动键盘鼠标了!');end;

只要用户动了鼠标或键盘,计数就会重新开始,GetLastInputInfo是核心
[/Quote]

这个好,谢谢,收下了。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧