原文: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 窗体中获取键盘和鼠标无操作时的超时提示的更多相关文章

  1. C#获取键盘和鼠标操作的时间的类

    /// /// 创建结构体用于返回捕获时间 /// [StructLayout(LayoutKind.Sequential)] struct LASTINPUTINFO { /// /// 设置结构体 ...

  2. C# 判断系统空闲(键盘、鼠标不操作一段时间)

    利用windows API函数 GetLastInputInfo()来判断系统空闲 //添加引用 using System.Runtime.InteropServices; // 创建结构体用于返回捕 ...

  3. .net中模拟键盘和鼠标操作

    原文:.net中模拟键盘和鼠标操作 周银辉 其实SendKeys类提供的方法蛮好用的,可惜的是WPF中不能用了,说是WPF的消息循环方式改成了Dispatcher,所以直接调用System.Windo ...

  4. Java中获取键盘输入值的三种方法

    Java中获取键盘输入值的三种方法     Java程序开发过程中,需要从键盘获取输入值是常有的事,但Java它偏偏就没有像c语言给我们提供的scanf(),C++给我们提供的cin()获取键盘输入值 ...

  5. Java编程中获取键盘输入实现方法及注意事项

    Java编程中获取键盘输入实现方法及注意事项 1. 键盘输入一个数组 package com.wen201807.sort; import java.util.Scanner; public clas ...

  6. 在WPF窗体中重绘

    原文:在WPF窗体中重绘   写这篇主要是为了验证任何元素自身都具备绘图功能. 在默认Window中重写OnRender方法 protected override void OnRender(Draw ...

  7. Vue 页面15分钟无操作时返回首页

    这种需求手机端和pc端一般是不存在的,因为都是可以手动操作刷新的. 最近在做一个户外社区大屏的项目,因为大屏是全屏显示,没法手动刷新,不可能在页面专门做一个刷新按钮,也不好看,那这样的需求就显得格外重 ...

  8. WPF 中模拟键盘和鼠标操作

    转载:http://www.cnblogs.com/sixty/archive/2009/08/09/1542210.html 更多经典文章:http://www.qqpjzb.cn/65015.ht ...

  9. 原生js中获取this与鼠标对象以及vue中默认的鼠标对象参数

    1.通过原生js获取this对象 <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...

随机推荐

  1. vim :g

    https://stackoverflow.com/questions/1946738/vim-how-to-delete-every-second-row An elegant (and effic ...

  2. 最简单的基于FFmpeg的移动端样例:IOS HelloWorld

    ===================================================== 最简单的基于FFmpeg的移动端样例系列文章列表: 最简单的基于FFmpeg的移动端样例:A ...

  3. ios开发runtime学习三:动态添加方法(实际应用少,面试)

    #import "ViewController.h" #import "Person.h" /* 1: Runtime(动态添加方法):OC都是懒加载机制,只要 ...

  4. linux ps命令,查看某进程cpu和内存占用率情况, linux ps命令,查看进程cpu和内存占用率排序。 不指定

    背景:有时需要单看某个进程的CPU及占用情况,有时需要看整体进程的一个占用情况.一. linux ps命令,查看某进程cpu和内存占用率情况[root@test vhost]# ps auxUSER  ...

  5. php 字符串 去掉 html标签

    echo strip_tags("Hello <b>world!</b>");

  6. 5.8 pprint--美观地打印数据

    pprint模块提供了一个美观地打印Python数据结构的方式.假设是要格式化的数据结构里包括了非基本类型的数据,有可能这样的数据类型不会被载入.比方数据类型是文件.网络socket.类等.本模块格式 ...

  7. Android自定义组件系列【1】——自定义View及ViewGroup

    View类是ViewGroup的父类,ViewGroup具有View的所有特性,ViewGroup主要用来充当View的容器,将其中的View作为自己孩子,并对其进行管理,当然孩子也可以是ViewGr ...

  8. [Vue] Use Vue.js Watchers to Respond to Async Updates

    Use watchers to keep an eye on your data. Watchers are methods that are invoked when the specified a ...

  9. 数据库使用truncate清理非常多表时碰到外键约束时怎么高速解决

    问题处理思路: 1. 先将数据库中涉及到外键约束的表置为无效状态 2.待清除全然部表数据后再将外键约束的表置为可用状态 详细实现脚本: declare begin for vv_sql in (SEL ...

  10. 【oracle11g ,19】索引管理

    一.索引的分类: 1.逻辑上分为:  单列索引和复合索引  唯一索引和非唯一索引  函数索引 domain索引 2.物理上分:  分区索引和非分区索引 b-tree  bitmap 注意:表和索引最好 ...