C#获取键盘和鼠标操作的时间的类
///
/// 创建结构体用于返回捕获时间
///
[StructLayout(LayoutKind.Sequential)]
struct LASTINPUTINFO
{
///
/// 设置结构体块容量
///
[MarshalAs(UnmanagedType.U4)]
public int cbSize;
/// <summary>
/// 抓获的时间
/// </summary>
[MarshalAs(UnmanagedType.U4)]
public uint dwTime;
}
[DllImport("user32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
/// <summary>
/// 获取键盘和鼠标没有操作的时间
/// </summary>
/// <returns>用户上次使用系统到现在的时间间隔,单位为秒</returns>
public static long GetLastInputTime()
{
LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
if (!GetLastInputInfo(ref vLastInputInfo))
{
return 0;
}
else
{
long count = Environment.TickCount - (long)vLastInputInfo.dwTime;
//long icount = count / 1000;
return count;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
int sunNumber=int.Parse(GetLastInputTime().ToString());
if (sunNumber >= 30000)
{
this.Close();
}
}
C#获取键盘和鼠标操作的时间的类的更多相关文章
- WPF 窗体中获取键盘和鼠标无操作时的超时提示
原文:WPF 窗体中获取键盘和鼠标无操作时的超时提示 通过调用Windows API中的GetLastInputInfo来获取最后一次输入的时间 , , ); timer.Tic ...
- WPF 中模拟键盘和鼠标操作
转载:http://www.cnblogs.com/sixty/archive/2009/08/09/1542210.html 更多经典文章:http://www.qqpjzb.cn/65015.ht ...
- Blender 工具使用——显示键盘和鼠标操作
Blender 工具使用--显示键盘和鼠标操作 Blender自己本身就带有显示按键和鼠标的功能,就是3D View: Screencast Keys插件. 打开 File(文件) -> Use ...
- .net中模拟键盘和鼠标操作
原文:.net中模拟键盘和鼠标操作 周银辉 其实SendKeys类提供的方法蛮好用的,可惜的是WPF中不能用了,说是WPF的消息循环方式改成了Dispatcher,所以直接调用System.Windo ...
- windows7如何用键盘模拟鼠标操作
windows7如何用键盘模拟鼠标操作 https://jingyan.baidu.com/article/6dad5075104907a123e36e38.html 听语音 37453人看了这个视频 ...
- Selenium_模拟键盘和鼠标操作(9)
模拟键盘键盘和鼠标操作主要使用到selenium的keys包,源码如下 class Keys(object): """ Set of special keys codes ...
- C# Stopwatch获取循环中某操作的时间消耗
在C#中通常使用DateTime来表示当前时间,可以在一个操作的前后分别使用一个DateTime对象获取当前时间,再将两个DateTime对象相减获得时间差(TimeSpan对象),从而得到这个操作耗 ...
- AJAX实现类似百度的搜索提示,自动补全和键盘、鼠标操作
<script type="text/javascript"> $(document).ready(function(){ var highlightIndex = - ...
- C# 判断系统空闲(键盘、鼠标不操作一段时间)
利用windows API函数 GetLastInputInfo()来判断系统空闲 //添加引用 using System.Runtime.InteropServices; // 创建结构体用于返回捕 ...
随机推荐
- C#泛型委托及约束
泛型委托: namespace 泛型委托 { public delegate void Mydelegate<T>(T msg); class Program { static void ...
- 免费DDOS攻击测试工具大合集
FreeBuf微科普: DoS(Denial Of Service)攻击是指故意的攻击网络协议实现的缺陷或直接通过野蛮手段残忍地耗尽被攻击对象的资源,目的是让目标计算机或网络无法提供正常的服务或资源访 ...
- 一.HttpClient、JsonPath、JsonObject运用
HttpClient详细应用请参考官方api文档:http://hc.apache.org/httpcomponents-client-4.5.x/httpclient/apidocs/index.h ...
- Oracle跨库访问数据表-DBLINK
1:创建DBLINK(USING后面的连接字符串就是要访问的那个数据库的连接字符串) CREATE DATABASE LINK linkName CONNECT TO userName IDENTIF ...
- 写入XML文件
public static void writeXMLFile(Document doc,String xmlFileName) throws IOException{ OutputFormat f ...
- 物流进程html+css页面
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> & ...
- Petya and Spiders【二进制状压】
题目链接[http://codeforces.com/problemset/problem/111/C] 题意:给出大小为N*M的图(1 ≤ n, m ≤ 40, n·m ≤ 40),每个图中有一个蜘 ...
- [转]URL的解析,C语言实现
http://blog.csdn.net/cuishumao/article/details/10284463 一 说明(1)应用情况:比如基于socket来实现http协议等,这时候就需要解析URL ...
- C/C++中整数与浮点数在内存中的表示方式
在C/C++中数字类型主要有整数与浮点数两种类型,在32位机器中整型占4字节,浮点数分为float,double两种类型,其中float占4字节,而double占8字节.下面来说明它们在内存中的具体表 ...
- linux中ssh登录Permanently added (RSA) to the list of known hosts问题解决
文章出自http://www.2cto.com/os/201307/227199.html linux中ssh登录Permanently added (RSA) to the list of know ...