在Windows上获取鼠标光标位置和按钮状态 [英] Getting mouse cursor position and button state on Windows
问题描述
在Windows(Windows 7及更高版本)上获取鼠标光标位置或按钮状态的最合适方法是什么?我以前使用过DirectInput,但是我不再使用它,也不希望这样做.我看到有GetCursorPos,但是,没有看到任何有关获取鼠标按钮状态的信息.以前,我已经读过,对于实时应用程序而言,仅读取窗口消息(例如WM_LBUTTONUP)被视为慢速",因此我不知道任何其他选项.
What is the most appropriate way of getting the mouse cursor position or button state on Windows (Windows 7 and above)? I previously used DirectInput, but I am not longer using it and do not wish to. I saw there is GetCursorPos, however, I do not see anything for getting mouse button states. I have read previously that just reading the window messages (such as WM_LBUTTONUP) was considered "slow" for real time applications, so I do not know of any other option.
推荐答案
如果要轮询/查询当前光标位置,可以使用 GetAsyncKeyState .
If you want to poll/query the current cursor position, you can use GetCursorPos. To see the button states, use GetAsyncKeyState.
如果您正在窗口中实现消息循环,则鼠标移动的通知将为此处.
If you are implementing a message loop in a window, the notification you will get for a mouse movement is WM_MOUSEMOVE. You will be notified of mouse inputs through the notifications listed here.
这篇关于在Windows上获取鼠标光标位置和按钮状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!