检测在表单显示之前是否已按下鼠标按钮
如果按下鼠标按钮并显示一个窗口,则释放鼠标按钮时该窗口将收到 MouseUp 事件。
一旦显示窗口,是否可以检测鼠标按钮是否已按下?
If a mouse button is pressed and a window is shown that window will receive the MouseUp event when the mouse button is released.
Is it possible to detect, once the window is shown, whether or not a mouse button is already pressed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会尝试这个:
I would try this:
要直接回答您的问题,您可以使用 < 测试鼠标按钮状态代码>GetKeyState 或
GetAsyncKeyState
。您需要的虚拟按键代码是VK_LBUTTON
。它们之间的区别在于,
GetKeyState
报告当前活动排队消息发布到队列时的状态。另一方面,GetAsynchKeyState
为您提供调用GetAsynchKeyState
时的状态。来自
GetKeyState
:我怀疑您应该使用
GetKeyState
但我不能 100% 确定,因为我实际上并不知道您想用此信息实现什么目的。To answer your question directly, you can test for mouse button state with
GetKeyState
orGetAsyncKeyState
. The virtual key code you need isVK_LBUTTON
.The difference between these is that
GetKeyState
reports the state at the time that the currently active queued message was posted to your queue. On the other hand,GetAsynchKeyState
gives you the state at the instant that you callGetAsynchKeyState
.From the documentation of
GetKeyState
:I suspect that you should be using
GetKeyState
but I can't be 100% sure because I don't actually know what you are trying to achieve with this information.