wpf 设置鼠标位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17900883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting mouse position?
提问by Jader J Rivera
Well I'm working on a small program and I'm trying to set the position of the window's mouse to it's center every time it moves. Thing is I have no idea how to make this work. I had the following code:
好吧,我正在开发一个小程序,每次移动时,我都试图将窗口鼠标的位置设置为它的中心。问题是我不知道如何进行这项工作。我有以下代码:
auto point = new Point(300.0, 200.0);
//auto ends up being Windows::Foundation::Point;
But I could still move the mouse freely all over the screen...
但是我仍然可以在整个屏幕上自由移动鼠标......
So then I searched the internet a bit and used:
然后我在互联网上搜索了一下并使用了:
Windows::UI::Input::PointerPoint point = Point(300.0, 200.0);//1
//and//
auto point = Windows::UI::Xaml::PointHelper::FromCoordinates(300.0, 200.0);//2
And example one wouldn't compile. Example 2 did compile but I could still move the mouse acrros the whole screen.
并且示例一不会编译。示例 2 确实编译了,但我仍然可以在整个屏幕上移动鼠标。
Don't know if it's important but I'm coding in C++, using DirectX for graphics and XAML for Text. (I'm also using the base class as C++/CX to work with XAML).
不知道这是否重要,但我使用 C++ 进行编码,将 DirectX 用于图形,将 XAML 用于文本。(我还使用基类作为 C++/CX 来处理 XAML)。
回答by Iosif Murariu
Try using SetCursorPos(), it should work on Windows.
尝试使用SetCursorPos(),它应该适用于 Windows。

