Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Idle time
#1
How can I calculate the Idle time of system?
#2
Use GetLastInputInfo.

Example. Function ResumeWhenIdle:
Code:
Copy      Help
;/
function [idletime] [flags] ;;flags: 1 remember active window

;This function pauses the macro

if(_winnt<5) ret

type LASTINPUTINFO cbSize dwTime
dll- user32 #GetLastInputInfo LASTINPUTINFO*plii

if(!idletime) idletime=10
idletime*1000

if(flags&1)
,int hfore=win

LASTINPUTINFO lii.cbSize=sizeof(LASTINPUTINFO)
int pause
rep
,GetLastInputInfo &lii
,int t=GetTickCount-lii.dwTime
,if(t>idletime) break
,pause=1
,1

if(pause and flags&1) spe 100; act hfore; err end _error
#3
Thanks.
#4
Is it possible in Windows 98?
#5
Needs to use keyboard and mouse hooks. They must be in a dll. I found one:

http://www.codeproject.com/dll/trackuseridle.asp

Download source files (you may need to register before you can download) and move IdleTrac.dll to QM folder.

Example:
Code:
Copy      Help
dll "IdleTrac.dll"
,[1]#IdleTrackerGetLastTickCount
,[2]#IdleTrackerInit
,[3]IdleTrackerTerm

if(!IdleTrackerInit) ret
atend IdleTrackerTerm

rep 10
,1
,out IdleTrackerGetLastTickCount
#6
Thanks again.
#7
Hi Gindi,

When I run this macro I get i=0. I was thinking I should see i=20?

Macro Macro1
Code:
Copy      Help
20
int i = GetIdleTime
out i
#8
Yes, should be 20 if you don't use the mouse, keyboard.
It is very simple function, just calls Windows API function GetLastInputInfo.
#9
Yes, but I don't. I get i=0. I am not touching the mouse or keyboard.

The reason I ask is because now the function below does not work for me either. I upgraded from XP to Win7 yesterday. This function below definitely used to work in XP. But it does not work in Win7 on my machine. I take it both of these work for you in Win7? Or if any other forum members can test in Win7 that would be appreciated. Maybe it's just my machine.


Function IdleTimeMinutes
Code:
Copy      Help
function#

type LASTINPUTINFO cbSize dwTime
dll- user32 #GetLastInputInfo LASTINPUTINFO*plii
LASTINPUTINFO lii.cbSize=sizeof(LASTINPUTINFO)
GetLastInputInfo &lii

int systemstarttime=GetTickCount/(60*1000)
int lastinput=lii.dwTime/(60*1000)

ret systemstarttime-lastinput
#10
GetIdleTime works here on Windows 7.
IdleTimeMinutes also should work.

GetLastInputInfo:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
#11
Yikes, sorry, I thought I had installed all Win7 updates. Some were missing. That was the problem.


Forum Jump:


Users browsing this thread: 1 Guest(s)