C# Win Form:检测上次交互(触摸)并显示确认框 [英] C# Win Form: Detect last interaction (touch) and display confirmation box

查看:34
本文介绍了C# Win Form:检测上次交互(触摸)并显示确认框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 窗体应用程序:

Windows Form Application:

有没有办法检查设备(Microsoft Surface 55 英寸触摸屏) 没有收到用户的任何交互(触摸)的时间,如果超过 5 分钟应该会显示一个确认框,询问您是要继续还是退出.在这 5 分钟内,将运行 Flash 文件或视频.如果视频正在运行(我在我的 Win Form 中嵌入了 AxWindowsMediaPlayer),那么它应该被暂停,然后应该显示确认框.

Is there a way to check the time for which the device (Microsoft Surface 55 inch touchscreen) hasn't received any interaction (touch) from the user and if it is more than 5 mins than a confirmation box should be displayed asking whether you want to continue or exit. For this 5 mins either a flash file or a video will be running. If the video is running (I have embedded AxWindowsMediaPlayer in my Win Form) then it should be paused and then the confirmation box should be displayed.

我想在 Visual Studio 2013 Professional 上使用 C# 代码来实现这一点.

I want to achieve this using C# code on Visual Studio 2013 Professional.

我遇到了一些函数和线程:

我发现的一个选项是使用 GetLastInputInfo() 函数.但是,我不确定它是否适用于触摸交互.我没有要测试的 Microsoft Surface 设备.引用自 MSDN:

One of the option i found is to use GetLastInputInfo() function. However, I am not sure whether it will work for touch interactivity. I don't have a Microsoft Surface device to test. A quote from MSDN:

此功能对于输入空闲检测很有用.但是,GetLastInputInfo 不会在所有正在运行的会话中提供系统范围的用户输入信息.相反,GetLastInputInfo 仅为调用该函数的会话提供特定于会话的用户输入信息.接收到最后一个输入事件时的滴答计数(请参阅 LASTINPUTINFO)不能保证是增量的.在某些情况下,该值可能小于先前事件的滴答计数.例如,这可能是由原始输入线程和桌面线程之间的时间间隔或 SendInput 引发的事件引起的,该事件提供自己的滴答计数.

This function is useful for input idle detection. However, GetLastInputInfo does not provide system-wide user input information across all running sessions. Rather, GetLastInputInfo provides session-specific user input information for only the session that invoked the function. The tick count when the last input event was received (see LASTINPUTINFO) is not guaranteed to be incremental. In some cases, the value might be less than the tick count of a prior event. For example, this can be caused by a timing gap between the raw input thread and the desktop thread or an event raised by SendInput, which supplies its own tick count.

我也遇到了 Application.idle 事件

如果有人对此有解决方法或有用的链接,我们将不胜感激.

Anyone has a workaround or useful links for this will be highly appreciated.

推荐答案

这段代码对我有用:

private void timer1_Tick(object sender, EventArgs e)
    {           
        tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO();
        Int32 IdleTime;
        LastInput.cbSize = (uint)Marshal.SizeOf(LastInput);
        LastInput.dwTime = 0;

        if (GetLastInputInfo(ref LastInput))
        {
            IdleTime = System.Environment.TickCount - LastInput.dwTime;
            if (IdleTime > 10000)
            {
                axWindowsMediaPlayer1.Ctlcontrols.pause();
                timer1.Stop();
                string timeRemaining = IdleTime.ToString();
                lbl_TimeRemaining.Text = IdleTime.ToString();
                lbl_TimeRemaining.Show();
                MessageBox.Show("Do you wish to continue?");
                lbl_TimeRemaining.Hide();
            }
            else
            {

            }
            timer1.Start();
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }            
        string title = axWindowsMediaPlayer1.currentMedia.getItemInfo("Title");
    }

第一次你必须通过从 FormLoad() 方法内部调用 timer1.start(); 来启动计时器

For the first time you will have to start the timer by calling timer1.start(); from inside the FormLoad() method

这篇关于C# Win Form:检测上次交互(触摸)并显示确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆