键盘鼠标空闲_如何锁定键盘鼠标
键盘鼠标空闲由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“如何锁定键盘鼠标”。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication2
{
public partial cla Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
timer2.Enabled = true;
}
[StructLayout(LayoutKind.Sequential)]
struct LASTINPUTINFO
{
[MarshalAs(UnmanagedType.U4)]
public int cbSize;
[MarshalAs(UnmanagedType.U4)]
public uint dwTime;
}
[DllImport(“user32.dll”)]
static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
static long GetLastInputTime()
{
LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);if(!GetLastInputInfo(ref vLastInputInfo))return 0;
return Environment.TickCount-(long)vLastInputInfo.dwTime;
}
private void timer1_Tick(object sender, EventArgs e){
if(GetLastInputTime()/1000+“”==“5”){
//此处可填写你需要的功能
MeageBox.Show(“任务执行”);
}
}
private void timer2_Tick(object sender, EventArgs e){
this.label1.Text =string.Format(“用户已经{0}秒没有路过了”, GetLastInputTime()/ 1000);
}
}
}