Skip to content

How can I set pointer position on SwapChainPanel in C#? #3427

Answered by castorix
vmx17 asked this question in Q&A
Discussion options

You must be logged in to vote

You can use APIs like SetCursorPos, SendInput or mouse_event and convert Screen to Client coordinates

Something like (test to position at 10, 10 inside a SwapChainPanel named scp1:

            IntPtr hWndMain = WinRT.Interop.WindowNative.GetWindowHandle(this);
            Windows.Graphics.PointInt32 pt = new Windows.Graphics.PointInt32(10, 10);
            ClientToScreen(hWndMain, ref pt);
            var gt = scp1.TransformToVisual((UIElement)this.Content);
            var ptNew = gt.TransformPoint(new Windows.Foundation.Point(0, 0));
            pt.X += (int)ptNew.X;
            pt.Y += (int)ptNew.Y;
            MoveCursor(pt.X, pt.Y);

with :

    [DllImport("User32.dll", ExactSpelling …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@vmx17
Comment options

Comment options

You must be logged in to vote
1 reply
@vmx17
Comment options

Answer selected by vmx17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants