在 OSX 上检测多设备应用程序中的空闲时间

Detect Idle Time in Multi-Device Application on OSX

我需要检测空闲时间,时间 因为用户已经在他们的机器上输入了任何东西,所以我之前只为 windows 制作了这个应用程序并且这个功能运行得非常好:-

function IdleTime: DWord;
var
  LastInput: TLastInputInfo;
begin
  LastInput.cbSize := SizeOf(TLastInputInfo);
  GetLastInputInfo(LastInput);
  Result := (GetTickCount - LastInput.dwTime) DIV 1000;
end;

但是,此功能不适用于多设备应用程序(据我所知)。我已经弄乱了一段时间,并进行了一些严格的谷歌搜索,但无济于事。

目标 OS 是 OS X 和 Windows。

OSX 上的 GetLastInputInfo 等价于 CGEventSourceCounterForEventType

参见:https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/func/CGEventSourceCounterForEventType

看这里:Detecting user-activity on mac os x

此调用的 API 接口位于:Macapi.CoreGraphics
因此,您需要将该单元添加到您的 uses 子句中。

如果您不熟悉 Delphi 下的 OSX 编程,请查看:https://delphihaven.wordpress.com