在Windows中使用两只鼠标执行完全不同的动作 [英] Using two mice to perform completely different actions in Windows

查看:124
本文介绍了在Windows中使用两只鼠标执行完全不同的动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试开发一个应用程序,以使用两只鼠标在Windows中执行完全不同的动作.但是,在花了几天的时间之后,我开始怀疑我想做的事是否甚至可以使用Windows API来完成.由于我还不是Windows API的专家,因此,我想征询您的意见,以了解我是朝正确的方向前进还是应该尝试完全不同的做法(也许是开发驱动程序?).

这是我要执行的操作:想象有两只鼠标插入我的计算机.我想将第一个鼠标用作普通鼠标,而第二个鼠标将用于执行完全不同的操作.例如,通过单击鼠标左键第二次,它将在Firefox中打开一个新选项卡(向Firefox应用程序发送CTRL + T命令),而当单击右键时,它将发送一个CTRL + C.然后,通过向上移动第二只鼠标,它将放大,而向下移动时,Firefox页面将缩小(因此,这样做时,屏幕上的鼠标光标将保持固定!).这个想法还可以识别当前使用的是哪个应用程序(哪个具有鼠标/键盘焦点),并根据该应用程序执行不同的操作.因此,例如,第二次鼠标左键单击将在FireFox中生成CTRL + T,在WORD中生成CTRL + B,在记事本中生成CTRL + S(实际上,其想法是随意设置这些动作的参数).所有这一切,而第一只鼠标必须继续像普通鼠标一样发挥作用.

因此,重要的是要了解我的应用程序将在后台运行,并且本质上不会直接与用户交互(没有GUI,因为它不需要用户输入任何内容).其目的仅仅是修改来自第二只鼠标的鼠标输入,并将其他输入(消息)发送到当前正在使用的应用程序.

到目前为止,我正在使用原始输入.在第二只鼠标上执行操作时,我能够区分使用的是哪只鼠标,并且能够向其他应用程序发送消息(特定于应用程序).当第二只鼠标移动时,我什至可以将光标锁定在屏幕上(这样,只有相应的消息会发送到感兴趣的应用程序!).但是,我无法用鼠标焦点阻止第二只鼠标发送给应用程序的按钮消息.因此,例如,在记事本中单击鼠标的第二个右键时,将发送我的特定命令(此刻为"aaa",为简便起见,我只是尝试使用字母),但该命令会显示在记事本窗口中.上下文记事本菜单也会打开……(因此也会收到WM_RBUTTONDOWN消息).

然后我的问题是:使用第二只鼠标时,如何阻止其他应用程序接收鼠标按钮消息((WM_RBUTTONDOWN等)?甚至可以吗?问题是(以我的理解)这些消息比WM_input messages具有更高的优先级...因此,当我在应用程序中读取WM_input消息并检测到第二只鼠标按下了按钮时,已经太迟了,并且WM_xBUTTONDOWN已经发送!)

我知道,使用鼠标挂钩可以阻止它们,但是,就没有办法区分消息的来源了(当然,检测使用的鼠标是我的应用程序的重点).

我也尝试过使用DirectInput8,但是它不再支持使用多个鼠标(Windows专门说要使用原始输入来达到这种效果).

所以,我想我知道您已经迷失了方向,甚至不知道我想做什么甚至可以实现.任何帮助都将非常受欢迎.

期待阅读您的回复.

解决方案

我本来打算提出钩子,但随后我读到您已经对此进行了研究.我想,解决您问题的最后方法是编写自己的驱动程序. Windows以通常的方式安装了第二个鼠标之后,您可以转到设备管理器",然后将要改用"鼠标的驱动程序更改为自己的驱动程序.

尽管,开发驱动程序可能无济于事,这是项目中的一项附带任务.

I'm currently trying to develop an application to use two mice to perform completely different actions in Windows. However, after having spent couple days on it, I'm starting to wonder if what I want to do is even possible using Windows APIs. As I'm far from being an expert in Windows APIs, I would like to get your opinions to know whether I'm going in the right direction or whether I should try to do it completely differently (maybe developing a driver ?).

Here's what I want to do : Imagine two mice are plugged in my computer. I would like to use the first one as a regular mouse, while the second one would be used to perform completely different actions. For instance, by clicking the second left mouse button, it would open a new tab in Firefox (sending a CTRL+T command to FireFox app) and when clicking the right button, it would send a CTRL+C. Then, by moving the second mouse upwards, it would zoom in, and when moving it downwards, the firefox page would zoom out (so the mouse cursor on screen would remain fix while doing that !). The idea is to recognize as well which application is currently used (which one has mouse/keyboard focus) and perform different actions depending on it. So for instance, the second mouse left click would generate a CTRL+T in FireFox, a CTRL+B in WORD and a CTRL+S in Notepad (in fact, the idea is to parameterize those actions at will). All of that while the first mouse must continue to act just as a regular mouse.

So, it's important to understand that my application will run in the background and will never, per se, interact directly with the user (no GUI as it doesn't require the user to input anything). Its purpose is just to modify the mouse inputs coming from the second mouse and send other inputs(messages) to the application currently being used.

So far, I'm using raw input. I'm able to differentiate which mouse is being used and I'm able to send messages (application specific) to other applications when an action is performed on the second mouse. I'm even able to lock the cursor on screen when the second mouse is moved (so as only the corresponding message is sent to the application of interest !). However, I'm unable to block the button messages sent by the second mouse to the app with the mouse focus. Hence, when clicking on the second mouse right button in Notepad for instance, my specific command ("aaa" for the moment as I'm just trying with letters for sake of simplicity) is sent (and displayed in the notepad window) BUT the contextual Notepad menu opens as well… (hence it's received as well a WM_RBUTTONDOWN message).

My question is then : How can I block the mouse button messages ((WM_RBUTTONDOWN, and so on…) to be received by other applications when the second mouse is used? Is it even possible ? The problem is that (in my understanding) those messages have higher priority over the WM_input messages… So when I read the WM_input message in my application and detects that the button was pressed from the second mouse, it's already too late and the WM_xBUTTONDOWN was already sent !)

I know that using the mouse hooks, I could block those but then, there is no way to differentiate the origin of the message (and of course, detecting which mouse is used is the main point of my application).

I've tried as well using DirectInput8 but it doesn't support anymore the usage of several mice (Windows specifically says to use raw input to this effect).

So, I guess that by know you've gotten that I'm quite lost and have no idea whether what I want to do it even achievable. Any help would be more than welcome.

Looking forward to reading your replies.

解决方案

I was about to suggest hooks, but then I read that you looked into that already. I guess, the last resort for your problem would be to write your own driver. After Windows installed the second mouse in it's usual way, you can go to the Device Manager and change the driver of the mouse you want to "repurpose" to your own driver.

Although, developing a driver is probably nothing one will do as a side task in a project.

这篇关于在Windows中使用两只鼠标执行完全不同的动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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