In my app I need to be able to get how long the user has been idle for. I wrote code for Windows to do this using LASTINPUTINFO and GetLastInputInfo_(), but I'm having much worse luck on the Mac. I saw people on places like Stackoverflow suggesting I run a terminal command (because of course; it's the Mac), but I can't get it to work. Here's my code:
Code: Select all
Procedure GetIdleTime()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Protected Info.LASTINPUTINFO
Info\cbSize = SizeOf(LASTINPUTINFO)
GetLastInputInfo_(@Info)
CompilerIf #PB_Compiler_32Bit
ProcedureReturn (GetTickCount_() - Info\dwTime) / (1000 * 60)
CompilerElse
ProcedureReturn (GetTickCount64() - Info\dwTime) / (1000 * 60)
CompilerEndIf
CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
Protected IOReg, Result$
IOReg = RunProgram("ioreg", "-c IOHIDSystem", GetCurrentDirectory(), #PB_Program_Read)
Result$ = ReadProgramString(IOReg)
CreateRegularExpression(0, "HIDIdleTime.*")
ExamineRegularExpression(0, Result$)
If NextRegularExpressionMatch(0)
Result$ = RegularExpressionMatchString(0)
EndIf
Debug Result$
ProcedureReturn Val(Result$)
CompilerEndIf
EndProcedure
Thanks.