Groups | Blog | Home
all groups > visual studio .net general > january 2007 >

visual studio .net general : GetLastInputInfo API



JAWinner
1/26/2007 8:11:02 PM
I am having trouble getting the GetLastInputInfo API to work in VB.NET 2005.
When I make the API call the value of dwTime is always returned as 0. I am
expecting the API to return the Tick Count of the last Mouse/KB Movement. I
can get it to work in VB6 but not VB.Net.

Here is the code.

Public Class Form1
Private Structure LASTINPUTINFO
Public cbSize As Long
Public dwTime As Integer
End Structure

Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetLastInputInfo Lib "user32" (ByRef plii As
LASTINPUTINFO) As Boolean


Private Sub Form1_Load1(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Command1.Text = "Stop"
Timer1.Interval = 10 'ms
Timer1.Enabled = True
End Sub

Private Sub Command1_Click1(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Command1.Click

If Command1.Text = "Start" Then
Timer1.Start()
Command1.Text = "Stop"
Else
Timer1.Stop()
Command1.Text = "Start"
End If
End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim lii As LASTINPUTINFO
lii.cbSize = Len(lii)
GetLastInputInfo(lii)

With Label1
.Text = "system idle (secs): " & FormatNumber((GetTickCount() -
lii.dwTime) / 1000, 2)
.Refresh()
End With
End Sub
End Class

Thanks,
John
Mattias Sjögren
1/28/2007 11:16:20 AM
[quoted text, click to view]

cbSize should be an Integer as well.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button