tags:

views:

179

answers:

2

I have a ruby script. I want to know how long the system has been idle (i.e. no user interaction - the time screen saver activation is based upon).

I believe I can do this in ruby via win32api using user32.dll and GetLastInputInfo, but I can't figure out how... can anyone can help me?

.

A: 

It would appear what you want to do has been done for Linux:

http://coderrr.wordpress.com/2008/04/20/getting-idle-time-in-unix/

But as for windows the nearest thing I could find is for C#... I don't have a windows machine to hack with but it could well give you an indication as to how GetLastInputInfo can be interacted with:

http://dataerror.blogspot.com/2005/02/detect-windows-idle-time.html

roja
+1  A: 

Here is a sample that calls GetLastInputInfo. I did not study that API, though, to see if it is really giving you the information you are wanting.

require "Win32API"

api = Win32API.new( 'user32', 'GetLastInputInfo', ['P'], 'I')
# match the structure LASTINPUTINFO. First 4 byte int is size of struct
s = [8, 0].pack('l*')
api.call( s )
a = s.unpack('l*')
puts a
Mark Wilkins