如何使用 Win32/User32 库检查当前鼠标按钮状态?
我知道如何使用 User32 SendInput 方法刺激点击,我需要的是类似的 User32 方法,但要获取当前的鼠标按钮状态。
类似于:
public static extern bool GetCursorPos(ref System.Drawing.Point lpPoint);
函数 GetCursorPos 为我提供当前光标位置。我需要的是左按钮状态(如果单击或未单击)。有这样的功能吗?
I know how to stimulate clicks using User32 SendInput method and what I need is a similar User32 method but to obtain the current mouse button state.
Something similar to:
public static extern bool GetCursorPos(ref System.Drawing.Point lpPoint);
Function GetCursorPos gives me the current cursor position. What I need is the left button state (if it's clicked or not). Is there such a function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个名为 GetAsyncKeyState 的方法。方法签名如下所示:
[DllImport("user32.dll")]
公共静态外部短 GetAsyncKeyState(UInt16 virtualKeyCode);
然后您只需通过传递鼠标左键代码 (VK_LBUTTON = 0x01) 来调用它即可。
更多信息直接来自 MSDN。
There's a method called GetAsyncKeyState. The method signature looks like this:
[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(UInt16 virtualKeyCode);
Then you simply call it passing the left mouse key code (VK_LBUTTON = 0x01) and off you go.
More information directly from MSDN.
使用GetAsyncKeyState,引用MSDN:
Use GetAsyncKeyState, To Quote MSDN: