Thread Rating:
  • 339 Vote(s) - 2.68 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PCで現在のOSのアイドル時間情報を知る方法
01-06-2016, 12:39 PM,
#2
RE: PCで現在のOSのアイドル時間情報を知る方法
Curlアプレットのウィンドウ内部に対する操作でしたら、get-gui-manager(プロシージャ)を使用して取得した
GuiManagerにKeyPressとPointerEventのイベントハンドラを追加して監視できそうですが、直接OSから
取得するとなると難しそうですね。

WindowsではCURL.LANGUAGE.DLL-INTERFACEを使用して、user32.dllのget-last-input-infoと
Kernel32.dllのget-tick-countを呼び出せばOSが持っているユーザが最後に入力した時刻からの
経過時間が計算できると思います。(残念ながらMac OSはよくわかりません)

試しにコードを書いてみましたが、こんな感じでしょうか。
Code:
{curl 8.0 applet}
{curl-file-attributes character-encoding = "utf8"}

{import * from CURL.LANGUAGE.DLL-INTERFACE}

{def
    UINT = int,
    DWORD = int32,
    BOOL = int
}

|| GetLastInputInfo関数の引数に指定するLASTINPUTINFO 構造体へのインターフェイス定義
|| see. https://msdn.microsoft.com/en-us/library/windows/desktop/ms646272.aspx
{define-C-struct public LASTINPUTINFO
  field public cbSize:UINT
  field public dwTime:DWORD
  def public size-of = 8 || sizeof LASTINPUTINFO
}

|| user32.dllのget-last-input-info関数を使用するための特別クラスの定義
|| see. https://msdn.microsoft.com/en-us/library/windows/desktop/ms646302.aspx
{define-dll-class public User32Dll
  {defaults
      calling-convention = stdcall,
      string-rep = CStringUTF16
  }
  
  {constructor public {default}
      {construct-super {SharedLibrary "user32.dll"}}
  }
  
  {dll-method public {get-last-input-info ("GetLastInputInfo")
                         pii:CPointer
                     }:BOOL
  }
}

|| Kernel32.dllのget-tick-count関数を使用するための特別クラスの定義
|| see. https://msdn.microsoft.com/en-us/library/ms724408.aspx
{define-dll-class public Kernel32Dll
  {defaults
      calling-convention = stdcall,
      string-rep = CStringUTF16
  }
  
  {constructor public {default}
      {construct-super {SharedLibrary "Kernel32.dll"}}
  }
  
  {dll-method public {get-tick-count ("GetTickCount")}:DWORD}
}


|| ユーザが最後に入力した時刻からの経過時間を取得するプロシージャ
{define-proc public {get-last-input-time}:int
    def user32 = {User32Dll}
    def kernel32 = {Kernel32Dll}
    def info = {LASTINPUTINFO}
    set info.cbSize = LASTINPUTINFO.size-of
    
    def ret = {user32.get-last-input-info
                  info
              }
    {if ret == 0 then
        || failure
        {error {get-last-win32-error}}
    }
    
    def tick = {kernel32.get-tick-count}
    def elapsed-time = tick - info.dwTime

    {return elapsed-time}
}

|| 表示
{value
    def td-time = {TextDisplay
                      width = 2cm,
                      halign = "right"
                  }

    {Frame
        {HBox
            "最後の入力からの経過時間",
            td-time,
            "ms"
        },
        {on e:AttachEvent at f:Frame do
            {Timer
                interval=1s,
                {on TimerEvent do
                    def time = {get-last-input-time}
                    set td-time.value = {String time}
                }
            }
        }
    }
}


Messages In This Thread
RE: PCで現在のOSのアイドル時間情報を知る方法 - by dyoshida - 01-06-2016, 12:39 PM
Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('1302')