Using two mice to do completely different things on Windows
I am currently trying to develop an application to use two mice to do completely different things on Windows. However, after spending a couple of days doing this, I'm starting to wonder if what I want to do is possible with the Windows API. Since I am far from being an expert on Windows API, I would like to know your opinion on whether I am going in the right direction or should I try to do it in a completely different way (maybe driver development?).
Here's what I want to do: Imagine that I have two mice connected on my computer. I would like to use the former as a normal mouse, and the latter to perform completely different actions. For example, pressing the second left mouse button will open a new tab in Firefox (by sending CTRL + T to the FireFox application), and by clicking the right button, it will send CTRL + C. Then, by moving the second mouse up, it will zoom in, and by moving it down, the firefox page will shrink (so the mouse cursor on the screen stays fixed while doing this!). The idea is to also recognize which application is currently in use (which has mouse / keyboard focus) and take different actions depending on that. So, for example, a second left click will generate CTRL + T in FireFox,CTRL + B in WORD and CTRL + S in Notepad (actually the idea is to parameterize these actions as desired). All this while the first mouse should continue to act like a normal mouse.
So, the important thing to understand is that my application will run in the background and will never interact directly with the user by itself (there is no GUI since it does not require the user to type anything). Its purpose is to simply change the mouse inputs coming from the second mouse and send other inputs (messages) to the application that is currently in use.
So far, I am using original input. I can distinguish which mouse is in use and I can send messages (application specific) to other applications when an action is performed on the second mouse. I can even lock the cursor on the screen when I move the second mouse (since only the corresponding message is sent to the application of interest!). However, I cannot block button messages sent by the second mouse to the application with the mouse focus. Hence, when I click the second right mouse button in Notepad, for example, my special command ("aaa" at the moment, when I'm just trying with letters for simplicity) is sent (and displayed in the notepad window). BUT the "Notepad" context menu also opens ... (hence it received the message as well WM_RBUTTONDOWN
).
My question is this: how can I block the mouse button messages (( WM_RBUTTONDOWN
etc ...) to be received by other applications when using a second mouse? Is this possible? The problem is that (in my understanding) these messages have a higher priority over WM_input messages
... So when I read the message WM_input
in my application and found that the button was pressed with the second mouse, it's already too late and WM_xBUTTONDOWN
already sent!)
I know that with mouse hooks I could block them, but then there was no way to distinguish the original message (and of course, determining which mouse is being used is the main point of my application).
I also tried using DirectInput8, but it no longer supports the use of multiple mice (Windows specifically says it uses the original input for this effect).
So, my guess is that knowing that you've figured out that I am completely lost and have no idea if I want to make it even achievable. Any help would be more than welcome.
We look forward to hearing from you.
source to share
I was going to suggest hooks, but then I read that you already looked into this. Probably in the latter case, for your problem it would be to write your own driver. After Windows has installed the second mouse in the usual way, you can go to Device Manager and change the mouse driver you want to repackage to your own driver.
Although, driver development probably won't do anything as a side task in the project.
source to share