-
Notifications
You must be signed in to change notification settings - Fork 697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: WinUI3 - Windows.Current is null, then how to set mouse pointer position? #7947
Comments
CoreWindow is documented to be outright unsupported in desktop applications. So yes, this is expected. As for moving the mouse pointer, don't forget, you are now in desktop application land. This means that SetCursorPos is available. The .NET framework also has classes like Cursor, or you could just platform invoke SetCursorPos. |
@DarranRowe Could you provide me with some sample code to do 'platform invoke' for WinUI (.Net6)? |
It is no different from using platform invoke in any other situation. You first set up the class to reference the native function:
and just call it: There is nothing special about the namespace or class name used here. You can also use using to get rid of the namespace name as you normally can with C#. The function name needs to match the exported if you don't provide the entry point in the DllImport attribute though. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment. |
3 similar comments
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment. |
Describe the bug
Maybe similar to this question: #2609
But here, it is focused on moving mouse pointer to a position.
For UWP, I did like this:
Window.Current.CoreWindow.PointerPosition = new Point(x, (y + 25.0) / scaleMultiplier);
But VS complains that Window.Current is null.
From this issue, #4152
I see that ProtectedCursor is there, but it is for the shape of mouse pointer.
Then, how can I move mouse pointer?
Steps to reproduce the bug
Steps to reproduce the behavior:
Expected behavior
Window.Current in Blank App, Packaged (WinUI in UWP) returns a window instance
Screenshots
No response
NuGet package version
No response
Windows version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: