That is importent it gives me panel1's coordinates, not all window. It is important to know that the X coordinate is based on the position from the left of the window while the Y coordinate is based on the top of the window. Object, ByVal e As System.EventArgs) Handles MyBase. i can get coordinates of mouse down and movements of panel1. Function: Private Function getMouseLoc() As Point getMouseLoc Me.PointToClient(Me.Cursor.Position) Return getMouseLoc End Function dim mouseLoc as point getMouseLoc() Or. Private Sub Form1_Load( ByVal sender As System. dim mouseLoc as point m圜ontrol.pointToClient(m圜ontrol.Cursor) This gets the location relative to the container Form, not the screen. Return CallNextHookEx(WH_MOUSE_LL, nCode, wParam, lParam) ' Display cursor coordinate on Libel1 and Label2 Private Function MouseHookProc( ByVal nCode As Int32, ByVal wParam As IntPtr, ByRef lParam As MSLLHOOKSTRUCT) As Int32 Give it a try and let me know if it doesn't work for you. The window does not have to be active to be detected.
_mouseHook = SetWindowsHookExW(WH_MOUSE_LL, _mouseProc, GetModuleHandleW(IntPtr.Zero), 0) Your code looks basically correct but let's make it complete: import turtle def getmouseclickcoor (x, y): print (x, y) turtle.onscreenclick (getmouseclickcoor) turtle.mainloop () The above works - all clicks on the window print the x & y coordinates to the console. The MouseGetPos command retrieves the current position of the mouse cursor, and optionally which. _mouseProc = New CallBack( AddressOf MouseHookProc) Private Declare Function GetModuleHandleW Lib "kernel32.dll" ( ByVal fakezero As IntPtr) As IntPtr Private Declare Function GetCurrentThreadId Lib "kernel32.dll" () As Integer Private Declare Function CallNextHookEx Lib "user32.dll" ( ByVal idHook As Int32, ByVal nCode As Int32, ByVal wParam As IntPtr, ByRef lParam As MSLLHOOKSTRUCT) As Int32 Private Declare Function UnhookWindowsHookEx Lib "user32.dll" ( ByVal hook As IntPtr) As Boolean
Private Declare Function SetWindowsHookExW Lib "user32.dll" ( ByVal idHook As Int32, ByVal HookProc As CallBack, ByVal hInstance As IntPtr, ByVal wParam As Int32) As IntPtr Private Delegate Function CallBack( ByVal nCode As Int32, ByVal wParam As IntPtr, ByRef lParam As MSLLHOOKSTRUCT) As Int32