鼠标在窗口外按下和释放
我有两个布尔值: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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
绝对有可能,但非常耗时。使用 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.