【发布时间】:2011-04-24 02:33:00
【问题描述】:
几周前我是 Qt 的新手。我正在尝试用 C++ 重写一个 C# 应用程序,现在已经有了很大一部分。我目前的挑战是找到一种检测系统空闲时间的方法。
在我的 C# 应用程序中,我从如下所示的某个地方窃取了代码:
public struct LastInputInfo
{
public uint cbSize;
public uint dwTime;
}
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LastInputInfo plii);
/// <summary>
/// Returns the number of milliseconds since the last user input (or mouse movement)
/// </summary>
public static uint GetIdleTime()
{
LastInputInfo lastInput = new LastInputInfo();
lastInput.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInput);
GetLastInputInfo(ref lastInput);
return ((uint)Environment.TickCount - lastInput.dwTime);
}
我还没有学会如何通过 DLL 导入或任何 C++ 等效项来引用 Windows API 函数。老实说,如果可能的话,我宁愿避免他们。此应用程序正在迁移到 Mac OSX,未来可能还会迁移到 Linux。
是否有特定于 Qt 的、独立于平台的方法来获取系统空闲时间?这意味着用户在 X 时间内没有触摸鼠标或任何键。
提前感谢您提供的任何帮助。
【问题讨论】:
标签: c# qt winapi cross-platform dllimport