检查鼠标LButton是否关闭? [英] Check if Mouse LButton is down?

查看:170
本文介绍了检查鼠标LButton是否关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查鼠标左键是否按下/拖动某些东西(我预先提到了第一种可能性)。

How do I check if the Left button of my mouse is currently pressed down/dragging something(I preffer the first possibility).

我试过Mouse.IsDraging,但没有结果。

I tried Mouse.IsDraging,but no result.

注意:我在我的应用程序中处理鼠标消息,所以如果它的WM是没有问题的,只是分享一个方法来完成我的任务。

NOTE: I handle mouse messages in my application so its no problem if its a WM,just share a way to accomplish my task.

推荐答案

有一个Windows API函数 GetAsyncKeyState() ,尽管它的名字也可用于获取鼠标按钮的状态。链接的文档直接包含您的问题的答案:

There is a Windows API function GetAsyncKeyState(), which despite its name is also usable to get the state of the mouse buttons. The linked documentation directly contains the answer to your question:


GetAsyncKeyState 函数工作用鼠标按钮。但是,它检查物理鼠标按钮的状态,而不是物理按钮映射到的逻辑鼠标按钮上。例如,调用 GetAsyncKeyState(VK_LBUTTON)始终返回左侧物理鼠标按钮的状态,无论是否映射到左侧或右侧逻辑鼠标按钮。您可以通过调用 GetSystemMetrics(SM_SWAPBUTTON)来确定系统当前的物理鼠标按键映射到逻辑鼠标按钮,返回 TRUE 如果鼠标按钮被交换了。

The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling GetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped.

结果类型是 short 检查最重要的位只是测试值是否为负数。

The result type is short, to check for the most significant bit just test whether the value is negative.

这篇关于检查鼠标LButton是否关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆