windows 如何获取光标位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2396576/
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
How to get the cursor position
提问by Jaguar
I want to know how to get the cursor position on Windows in c++,
我想知道如何在 c++ 中获取 Windows 上的光标位置,
Reasons: I try to move the mouse position on X Y coordinate with the screen information
原因:我尝试用屏幕信息在XY坐标上移动鼠标位置
e.g: i want to set the mouse position in the offset x:576 y:854 on the screen.
例如:我想在屏幕上的偏移 x:576 y:854 中设置鼠标位置。
The only method that I found for do that is:
我找到的唯一方法是:
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE|MOUSEEVENTF_LEFTDOWN,x,y,0,0);
Normally the flag MOUSEEVENTF_ABSOLUTE is to do that but it doesn't work, that's why i try to get the absolute position of the mouse and try to calculate that !
通常标志 MOUSEEVENTF_ABSOLUTE 是这样做的,但它不起作用,这就是为什么我尝试获取鼠标的绝对位置并尝试计算它!
Thank you for your answer !
谢谢您的回答 !
回答by Péter T?r?k
Try GetCursorPos().