jes12345
asked on
Find time since last user input in VB .NET
Does anyone know a way to find the time since the last user input (mouse or keyboard). I do not want this to effect system performance so I do not think it is a good idea to capture all user input so I am hoping someone knows about an alternative way. Thanks J
VB Translation:
<DllImport("user32.dll")> _
Shared Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As Boolean
End Function
Friend Structure LASTINPUTINFO
Public cbSize As UInt;
Public dwTime As UInt;
End Structure
ASKER
In order to get it to work I had to put the code in a module. However the objects time is 0 even after the sleep.
Module Module1
Public Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As Boolean
End Function
Friend Structure LASTINPUTINFO
Public cbSize As Integer
Public dwTime As Integer
End Structure
End Module
'AND
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Threading.Thread.Sleep(15000)
Dim test As New LASTINPUTINFO
GetLastInputInfo(test)
MsgBox(test.dwTime)
End Sub
End Class
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If I understand correctly, this only applies to your application; it is not system wide.
ASKER
Sorry kaufmed but I did not understand your last question. Can I please ask you to elaborate?
Thanks J
Thanks J
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok I understand.Thank you for your replies. What I need is really a systemwide function. From reading the article it suggest to create a service using GetLastInputInfo() but that will not be possible on the design. Can you think of any other way of obtaining this? - if not I will find another design approach if installing a service is not an option.
Thanks J
Thanks J
You could implement some low-level hooks in conjunction with a timer. The low-level hooks will intercept the keyboard/mouse interactions and with each interception, you could restart the timer.
ASKER
I guess that would be an option - do you think this would be ok with regards to system performance? Thank you so much for all your help and advises. Before I close this thread and assign the points can I please ask if you have an example of an efficient way of caturing key/mouse system wide? Thanks J
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Fantastic - I will definately be able to use this for my solution. Thank you so much for all your advises and help kaufmed! J
ASKER
Good answer!
http://www.codeproject.com/KB/cs/GetIdleTimeWithCS.aspx