D
Damjan Malis
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 OpenInputDesktop to determine whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned by OpenInputDesktop 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_SWITCHDESKTOP As Int32 = &H100&
Private Const DESKTOP_READOBJECTS = &H1&
Private Const DESKTOP_WRITEOBJECTS = &H80&
Declare Function GetCursorPos Lib "User32" (ByRef lpPoint As Point) As Long
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function OpenInputDesktop(ByVal dwFlags As Integer, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Integer) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function SetThreadDesktop(ByVal hDesktop As Int32) As Int32
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function OpenDesktop(ByVal lpszDesktop As String, ByVal dwFlags As Integer, ByVal fInderit As Boolean, ByVal dwDesiredAccess As Integer) As IntPtr
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim xx As IntPtr = OpenInputDesktop(0, True, DESKTOP_SWITCHDESKTOP)
SetThreadDesktop(xx)
Dim pt As Point
GetCursorPos(pt)
ListBox1.Items.Add(pt.X.ToString + " x " + pt.Y.ToString)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 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
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 OpenInputDesktop to determine whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned by OpenInputDesktop 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_SWITCHDESKTOP As Int32 = &H100&
Private Const DESKTOP_READOBJECTS = &H1&
Private Const DESKTOP_WRITEOBJECTS = &H80&
Declare Function GetCursorPos Lib "User32" (ByRef lpPoint As Point) As Long
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function OpenInputDesktop(ByVal dwFlags As Integer, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Integer) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function SetThreadDesktop(ByVal hDesktop As Int32) As Int32
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function OpenDesktop(ByVal lpszDesktop As String, ByVal dwFlags As Integer, ByVal fInderit As Boolean, ByVal dwDesiredAccess As Integer) As IntPtr
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim xx As IntPtr = OpenInputDesktop(0, True, DESKTOP_SWITCHDESKTOP)
SetThreadDesktop(xx)
Dim pt As Point
GetCursorPos(pt)
ListBox1.Items.Add(pt.X.ToString + " x " + pt.Y.ToString)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 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