鼠标在窗口外按下和释放

发布于 2025-01-07 11:31:57 字数 122 浏览 5 评论 0原文

我有两个布尔值:leftPressed 和 rightPressed。我需要在按下各自的鼠标按钮时将它们设置为 true,在未按下时将它们设置为 false。鼠标的位置以及程序是否具有焦点都无关紧要。该程序没有 GUI。这可能吗?

I have two booleans: leftPressed and rightPressed. I need them to be set true when their respective mouse buttons are pressed and false when they are not. The location of the mouse and whether or not the program has focus should not matter. This program will not have a GUI. Is this even possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

著墨染雨君画夕 2025-01-14 11:31:57

绝对有可能,但非常耗时。使用 JNA 创建全局 mousehook。您必须为计划运行的每个平台提供实现,等等。例如, 有人用 Windows 做到了这一点

我曾一度在寻找类似的东西,但在我的代码中找到了一种更好的方法。不过,我确实遇到了这个。它可能适合你。

Definitely possible, very time consuming though. Use JNA to create a global mousehook. You would have to provide implementations for each platform you planned for it to run on, etc.. For example, here's someone who did it with windows.

I was looking for something similar at one point but found a better way to go about it in my code. However, I did run into this library. It may work out for you.

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