3

I need to detect Idle Time, Time Since the user has input anything into their machine, I've made this application before for windows only and this function worked brilliantly :-

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

However, this function doesn't work on Multi-Device Application(as far as I can tell). I've messed around with this for a while now and done some severe googling to no avail.

The target OS is OS X and Windows.

Johan
  • 74,508
  • 24
  • 191
  • 319
Miles
  • 63
  • 5
  • `GetLastInputInfo` works across the entire user session - is this what you are looking for? Not just your application, but any user input to any application on the device? – J... Mar 18 '16 at 12:10
  • If yes, I don't think FMX has anything ready-built for this. For OSX/Win I would expect you to need to do this conditionally using WinAPI for the latter and probably `ioreg` for OSX. A shell script example here : http://stackoverflow.com/a/17966890/327083 – J... Mar 18 '16 at 12:22
  • J, Exactly, I want to detect when someone has walked away from their machine for X amount of time, with no input during that time. I'll have a look into that, thanks :) – Miles Mar 18 '16 at 12:25
  • Removed *pascal* tag. Nnless you can tell us what plain old Pascal compiler you're using that does multi-device applications, Delphi or C++ Builder would be the only applicable language tags here. Please don't just add random tags because they have familiar words in them; tags here have specific meanings. If you're not sure if the tag applies, read it's description. If you're still not absolutely sure it applies, don't use it. – Ken White Mar 18 '16 at 17:22
  • Obviously your Delphi version is not 2010 if you're targeting osx. I've updated the tag to Delphi Seattle. Please correct me if I'm mistaken. – Johan Mar 19 '16 at 17:31
  • Ken, Johan, Sorry for the mistakes, First time posting and all, Thanks for the corrections, that was correct, I am using 10 Seattle. – Miles Mar 21 '16 at 12:17

1 Answers1

2

The equivalent of GetLastInputInfo on OSX is CGEventSourceCounterForEventType.

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

See here: Detecting user-activity on mac os x

The API interface for this call is in: Macapi.CoreGraphics
So you'll need to add that unit to your uses clause.

If you're not familair with OSX programming under Delphi, have a look at:https://delphihaven.wordpress.com

Community
  • 1
  • 1
Johan
  • 74,508
  • 24
  • 191
  • 319
  • Brilliant, Exactly what I was looking for, Marking this as Correct answer, Thanks to everyone else for their input too. – Miles Mar 21 '16 at 12:18