C# Win Form:检测最后一次交互(触摸)并显示确认框

C# Win Form: Detect last interaction (touch) and display confirmation box

Windows 申请表:

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

我想在 Visual Studio 2013 Professional.

上使用 C# 代码实现此目的

我遇到了一些函数 threads:

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

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事件

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

这段代码对我有用:

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(); 来启动计时器