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" ...
随机推荐
- [Angular] Separating Structural Styles From Theme Styles - Making Components Themeable
For the component's css file, we can improt two css files: common.css default-theme.css @import &quo ...
- linux下如何获取每个线程的CPU占用率
啥也不说,直接上脚本: root@Storage:/mnt/mtd# cat cpu.sh #!/bin/sh while truedo ps -H -eo user,pid,ppid, ...
- angular项目中各个文件的作用
原文地址 https://www.jianshu.com/p/176ea79a7101 大纲 1.对angular项目中的一些文件的概述 2.对其中一些文件的详细描述 2.1.package.json ...
- java之 ------ 枚举类型
枚举 一.枚举类型具体说明 简单的说.Enum一般用来表示一组同样类型的常量. 如性别.日期.月份.颜色等.对这些属性用常量的优点是显而易见的,不仅能够保证单例,且在比較的时候能够用"==& ...
- Windows Phone 8.1 数据处理
Windows Phone 8.1 应用的数据存储位置包括: Installation Folder ApplicationData Credential Locker Known Folders S ...
- [Webpack] Access Webpack Dev Server from Mobile Safari on an iPhone
Testing your sites on mobile devices is a critical part of the development process. Webpack dev serv ...
- 【54.38%】【BZOJ 4300】绝世好题
Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1120 Solved: 609 [Submit][Status][Discuss] Descript ...
- Android 调整透明度的图片查看器
本文以实例讲解了基于Android的可以调整透明度的图片查看器实现方法,具体如下: main.xml部分代码如下: <?xml version="1.0" encoding ...
- web项目中配置多个数据源
web项目中配置多个数据源 spring + mybatis 多数据源配置有两种解决方案 1.配置多个不同的数据源,使用一个sessionFactory,在业务逻辑使用的时候自动切换到不同的数据源, ...
- js的dom对象(带实例超详细全解)
js的dom对象(带实例超详细全解) 一.总结 一句话总结: 1.DOM中的方法区分大小写么? 解答:区分 2.DOM中元素和节点的关系式什么? 解答:元素就是标签,节点中有元素节点,也是标签,节点中 ...