Hi guys...
could anyone please help me with my problem getting mouse cursor position while desktop being locked (WIN + L).
MSDN says:
"The input desktop must be the current desktop when you call GetCursorPos. Call OpenInputDeskto p to determine whether the current desktop is the input desktop. If it is not, call SetThreadDeskto p with the HDESK returned by OpenInputDeskto p to switch to that desktop."
src: http://msdn2.microsoft.com/en-us/library/ms648390.aspx
So I tried the following:
Imports System.Runtime. InteropServices
Public Class Form1
Private Const DESKTOP_SWITCHD ESKTOP As Int32 = &H100&
Private Const DESKTOP_READOBJ ECTS = &H1&
Private Const DESKTOP_WRITEOB JECTS = &H80&
Declare Function GetCursorPos Lib "User32" (ByRef lpPoint As Point) As Long
<DllImport("use r32.dll", SetLastError:=T rue)_
Private Shared Function OpenInputDeskto p(ByVal dwFlags As Integer, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Integer) As IntPtr
End Function
<DllImport("use r32.dll", SetLastError:=T rue)_
Private Shared Function SetThreadDeskto p(ByVal hDesktop As Int32) As Int32
End Function
<DllImport("use r32.dll", SetLastError:=T rue)_
Private Shared Function OpenDesktop(ByV al lpszDesktop As String, ByVal dwFlags As Integer, ByVal fInderit As Boolean, ByVal dwDesiredAccess As Integer) As IntPtr
End Function
Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles Timer1.Tick
Dim xx As IntPtr = OpenInputDeskto p(0, True, DESKTOP_SWITCHD ESKTOP)
SetThreadDeskto p(xx)
Dim pt As Point
GetCursorPos(pt )
ListBox1.Items. Add(pt.X.ToStri ng + " x " + pt.Y.ToString)
End Sub
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
End Sub
End Class
But sadly, it doesn't work. After desktop gets locked all I get is 0 x 0 for x and y coordinates.
Maybe you can recommend me some different approach to observe mouse movement activity from windows service. After all, I don't need exact coordinates, all I need is to determine if someone is using the mouse.
Thank you in advance.
Cheers,
Damjan
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com