【问题标题】:how to get window os system idle time using ruby?如何使用 ruby​​ 获取窗口操作系统系统空闲时间?
【发布时间】:2010-01-26 18:54:37
【问题描述】:

我有一个 ruby​​ 脚本。我想知道系统空闲了多长时间(即没有用户交互 - 屏幕保护程序激活的时间基于)。

我相信我可以通过 win32api 使用 user32.dll 和 GetLastInputInfo 在 ruby​​ 中做到这一点,但我不知道如何......谁能帮助我?

.

【问题讨论】:

    标签: ruby winapi


    【解决方案1】:

    这是一个调用 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
    

    【讨论】:

      【解决方案2】:

      看起来你想做的事情已经在 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

      【讨论】:

        【解决方案3】:

        根据 Mark Wilkins 的回答,我创建了一些脚本来记录用户的空闲时间。

        https://gist.github.com/Largo/11216868

        【讨论】:

          猜你喜欢
          • 2011-04-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-09-18
          相关资源
          最近更新 更多