我是几周前开始接触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。
非常感谢您提供的任何帮助。