【发布时间】:2010-01-26 18:54:37
【问题描述】:
我有一个 ruby 脚本。我想知道系统空闲了多长时间(即没有用户交互 - 屏幕保护程序激活的时间基于)。
我相信我可以通过 win32api 使用 user32.dll 和 GetLastInputInfo 在 ruby 中做到这一点,但我不知道如何......谁能帮助我?
.
【问题讨论】:
我有一个 ruby 脚本。我想知道系统空闲了多长时间(即没有用户交互 - 屏幕保护程序激活的时间基于)。
我相信我可以通过 win32api 使用 user32.dll 和 GetLastInputInfo 在 ruby 中做到这一点,但我不知道如何......谁能帮助我?
.
【问题讨论】:
这是一个调用 GetLastInputInfo 的示例。不过,我没有研究那个 API,看它是否真的给了你想要的信息。
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
【讨论】:
看起来你想做的事情已经在 Linux 上完成了:
http://coderrr.wordpress.com/2008/04/20/getting-idle-time-in-unix/
但至于 windows,我能找到的最接近的东西是 C#... >
http://dataerror.blogspot.com/2005/02/detect-windows-idle-time.html
【讨论】:
根据 Mark Wilkins 的回答,我创建了一些脚本来记录用户的空闲时间。
【讨论】: