Last active
September 10, 2024 04:36
-
-
Save papinko/da2caa26e8ae16f24b54f20c36aff7aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DllImport("user32.dll")] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
static extern bool GetCursorPos(ref Win32Point pt); | |
[StructLayout(LayoutKind.Sequential)] | |
struct Win32Point | |
{ | |
public Int32 X; | |
public Int32 Y; | |
}; | |
public static Point GetCurrentCursorPosition(Visual relativeTo) | |
{ | |
Win32Point w32Mouse = new Win32Point(); | |
GetCursorPos(ref w32Mouse); | |
if (relativeTo == null) | |
return new Point(w32Mouse.X, w32Mouse.Y); | |
else | |
return relativeTo.PointFromScreen(new Point(w32Mouse.X, w32Mouse.Y)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment