How can I get the time of the last input event (key and mouseactivity) in VISTA?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tomas

    How can I get the time of the last input event (key and mouseactivity) in VISTA?

    I have done a small program in VB.NET that uses the GetLastInputInf o
    function to retrieve the time of the last input event. It checks every
    second and it works well in Windows XP. However, when I install the
    program in VISTA it crashes.

    Does anyone know how I can get the time of the last input event (key
    and mouse activity) in VISTA?

    Any direction and help is most appreciated!

    Best regards,

    Tomas :)
  • Chris Dunaway

    #2
    Re: How can I get the time of the last input event (key and mouseactivity) in VISTA?

    On Jun 26, 4:52 am, Tomas <tomas_nordlan. ..@yahoo.comwro te:
    However, when I install the program in VISTA it crashes.
    You're going to have to be a little more specific. What does "it
    crashes" mean? Are you getting an exception? Does the program just
    fail to run? What version of Vista are you running it on? Can you
    post a short but complete program that demonstrates the problem?

    Chris

    Comment

    • Joergen Bech

      #3
      Re: How can I get the time of the last input event (key and mouse activity) in VISTA?


      Works fine here. The ugly sample code below was quickly hacked
      together from pinvoke.net. It has been tested on XP SP3 and Vista x64.

      The question is whether you are running this as a normal application
      or as a service. The latter might cause some problems, according to
      discussions on the web.

      Regards,

      Joergen Bech

      ---snip---
      Option Explicit On
      Option Strict On

      Imports System.Runtime. InteropServices

      Public Class Form1
      <DllImport("use r32.dll")_
      Shared Function GetLastInputInf o(ByRef plii As LASTINPUTINFO) As
      Boolean
      End Function

      <StructLayout(L ayoutKind.Seque ntial)_
      Structure LASTINPUTINFO
      <MarshalAs(Unma nagedType.U4)_
      Public cbSize As Integer
      <MarshalAs(Unma nagedType.U4)_
      Public dwTime As Integer
      End Structure


      Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
      System.EventArg s) Handles Timer1.Tick
      DisplayTime()
      End Sub


      Dim idletime As Integer
      Dim lastInputInf As New LASTINPUTINFO()

      Public Function GetLastInputTim e() As Integer

      idletime = 0
      lastInputInf.cb Size = Marshal.SizeOf( lastInputInf)
      lastInputInf.dw Time = 0

      If GetLastInputInf o(lastInputInf) Then
      idletime = Environment.Tic kCount - lastInputInf.dw Time
      End If

      If idletime 0 Then
      Return idletime \ 1000
      Else
      Return 0
      End If

      End Function

      Private Sub DisplayTime()
      Label1.Text = GetLastInputTim e.ToString
      End Sub

      End Class
      ---snip---






      On Thu, 26 Jun 2008 02:52:07 -0700 (PDT), Tomas
      <tomas_nordland er@yahoo.comwro te:
      >I have done a small program in VB.NET that uses the GetLastInputInf o
      >function to retrieve the time of the last input event. It checks every
      >second and it works well in Windows XP. However, when I install the
      >program in VISTA it crashes.
      >
      >Does anyone know how I can get the time of the last input event (key
      >and mouse activity) in VISTA?
      >
      >Any direction and help is most appreciated!
      >
      >Best regards,
      >
      >Tomas :)

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: How can I get the time of the last input event (key and mouse activity) in VISTA?

        "Tomas" <tomas_nordland er@yahoo.comsch rieb:
        >I have done a small program in VB.NET that uses the GetLastInputInf o
        function to retrieve the time of the last input event. It checks every
        second and it works well in Windows XP. However, when I install the
        program in VISTA it crashes.
        You can find a working sample here:

        <URL:http://dotnet.mvps.org/dotnet/code/misc/#UserIdle>

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

        Comment

        Working...