Reputation: 29
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?
.
Upvotes: 3
Views: 771
Reputation: 330
On the basis of the answer from Mark Wilkins, I created some script to log the idle time of a user.
https://gist.github.com/Largo/11216868
Upvotes: 0
Reputation: 41252
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
Upvotes: 3
Reputation: 2354
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
Upvotes: 0