WPF 窗体中获取键盘和鼠标无操作时的超时提示
通过调用Windows API中的GetLastInputInfo来获取最后一次输入的时间
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;using System.Runtime.InteropServices;namespace WpfApplication1{ /// <summary> /// Window1.xaml 的交互逻辑 /// </summary> public partial class Window1 : Window { System.Windows.Threading.DispatcherTimer timer; public Window1() { InitializeComponent(); timer = new System.Windows.Threading.DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 1); timer.Tick += new EventHandler(timer_Tick); timer.Start(); } void timer_Tick(object sender, EventArgs e) { if (GetIdleTick() / 1000 > 10) { MessageBox.Show("键盘或鼠标没有操作超过10秒"); } } [DllImport("user32.dll")] static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); public static long GetIdleTick() { LASTINPUTINFO lastInputInfo = new LASTINPUTINFO(); lastInputInfo.cbSize = Marshal.SizeOf(lastInputInfo); if (!GetLastInputInfo(ref lastInputInfo)) return 0; return Environment.TickCount - (long)lastInputInfo.dwTime; } [StructLayout(LayoutKind.Sequential)] private struct LASTINPUTINFO { [MarshalAs(UnmanagedType.U4)] public int cbSize; [MarshalAs(UnmanagedType.U4)] public uint dwTime; } }}
WPF 窗体中获取键盘和鼠标无操作时的超时提示的更多相关文章
- C#获取键盘和鼠标操作的时间的类
/// /// 创建结构体用于返回捕获时间 /// [StructLayout(LayoutKind.Sequential)] struct LASTINPUTINFO { /// /// 设置结构体 ...
- C# 判断系统空闲(键盘、鼠标不操作一段时间)
利用windows API函数 GetLastInputInfo()来判断系统空闲 //添加引用 using System.Runtime.InteropServices; // 创建结构体用于返回捕 ...
- .net中模拟键盘和鼠标操作
原文:.net中模拟键盘和鼠标操作 周银辉 其实SendKeys类提供的方法蛮好用的,可惜的是WPF中不能用了,说是WPF的消息循环方式改成了Dispatcher,所以直接调用System.Windo ...
- Java中获取键盘输入值的三种方法
Java中获取键盘输入值的三种方法 Java程序开发过程中,需要从键盘获取输入值是常有的事,但Java它偏偏就没有像c语言给我们提供的scanf(),C++给我们提供的cin()获取键盘输入值 ...
- Java编程中获取键盘输入实现方法及注意事项
Java编程中获取键盘输入实现方法及注意事项 1. 键盘输入一个数组 package com.wen201807.sort; import java.util.Scanner; public clas ...
- 在WPF窗体中重绘
原文:在WPF窗体中重绘 写这篇主要是为了验证任何元素自身都具备绘图功能. 在默认Window中重写OnRender方法 protected override void OnRender(Draw ...
- Vue 页面15分钟无操作时返回首页
这种需求手机端和pc端一般是不存在的,因为都是可以手动操作刷新的. 最近在做一个户外社区大屏的项目,因为大屏是全屏显示,没法手动刷新,不可能在页面专门做一个刷新按钮,也不好看,那这样的需求就显得格外重 ...
- WPF 中模拟键盘和鼠标操作
转载:http://www.cnblogs.com/sixty/archive/2009/08/09/1542210.html 更多经典文章:http://www.qqpjzb.cn/65015.ht ...
- 原生js中获取this与鼠标对象以及vue中默认的鼠标对象参数
1.通过原生js获取this对象 <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
随机推荐
- Envelope
IEnvelope Interface Provides access to methods and properties of envelopes. Note: the IEnvelope inte ...
- div宽度设置width:100%后再设置padding或margin超出父元素的解决办法
div宽度设置width:100%后再设置padding或margin超出父元素的解决办法 一.总结 一句话总结:直接加上box-sizing:border-box;即可解决上述问题. 1.box-s ...
- php压缩
php压缩的一个demo,随便测试了一下,可以用 <?php class PHPZip { private $ctrl_dir = array(); private $datasec = arr ...
- 嵌入式linux串口编程(二)
/*com_writer.c*/#include "uart_api.h" int main(void){ int fd; char buff[BUFFER_SIZE]; if(( ...
- Oracle 12C R2 on Linux 7.X 单实例静默安装文档
禁用防火墙systemctl stop firewalld.servicesystemctl disable firewalld.service 禁用SELinuxcat /etc/selinux/c ...
- Drupal 7 模块开发 建立模块帮助信息(hook_help)
建立模块请參考 <Drupal 7 模块开发 建立> 假设你要支持中文,文件格式必须保存为 UTF-8.NO BOM ------------------------------ hook ...
- php字符串转时间戳
PHP 提供了函数可以方便的将各种形式的日期转换为时间戳,该类函数主要是: strtotime():将任何英文文本的日期时间描述解析为时间戳. mktime():从日期取得时间戳. strtotime ...
- OpenGL核心之视差映射
笔者介绍:姜雪伟,IT公司技术合伙人.IT高级讲师,CSDN社区专家,特邀编辑.畅销书作者;已出版书籍:<手把手教你¯的纹理坐标偏移T3来对fragment的纹理坐标进行位移.你能够看到随着深度 ...
- Android JNI -基础篇
JNI(Java Native Interface,JAVA本地接口) 可以使Java代码和其他语言写的代码(如C/C++代码)进行交互.为什么要进行交互? 首先,Java语言提供的类库无法满足要求, ...
- Opencv中使用Surf特征实现图像配准及对透视变换矩阵H的平移修正
图像配准需要将一张测试图片按照第二张基准图片的尺寸.角度等形态信息进行透视(仿射)变换匹配,本例通过Surf特征的定位和匹配实现图像配准. 配准流程: 1. 提取两幅图像的Surf特征 2. 对Sur ...