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

标签 c# winforms user-interface touch pixelsense

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

关于C# Win 表单 : Detect last interaction (touch) and display confirmation box,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33521384/

相关文章:

c# - WinForms 中的模型 View 展示器

c# - 使用 SMTP 在邮件正文中发送多个文本框值

预测语言偏好的 Android/iOS API/机制

java - 是否可以将 JCheckBox 放入不包含 boolean 值的 JTable 单元格中?

matlab - 如何在 MATLAB 中设置以编程方式调整大小的 UI

c# - 如何绑定(bind)到 DynamicResource 以便可以使用 Converter 或 StringFormat 等? (修订版 4)

c# - 您会使用什么报告工具?

c# - 如何设置多个自定义字段? - 微软项目服务器

c# - 为什么 ComboBox 在设置 DataSource 时不抛出异常?

c# - 插入数据并检查重复记录