如何使用 Win32/User32 库检查当前鼠标按钮状态?

发布于 2024-09-06 16:02:56 字数 233 浏览 0 评论 0原文

我知道如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情深缘浅 2024-09-13 16:02:56

有一个名为 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.

裸钻 2024-09-13 16:02:56

使用GetAsyncKeyState,引用MSDN:

GetAsyncKeyState 函数有效
与鼠标按钮。但是,它检查
关于物理鼠标的状态
按钮,不在逻辑鼠标上
物理按钮的按钮
映射到.例如,调用
始终 GetAsyncKeyState(VK_LBUTTON)
返回左侧物理的状态
鼠标按钮,无论是否
映射到左或右逻辑
鼠标按钮。您可以确定
系统当前的物理映射
鼠标按钮到逻辑鼠标按钮
通过致电
获取系统指标(SM_SWAPBUTTON)。

Use GetAsyncKeyState, To Quote MSDN:

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文