Is it possible to make a USB device that would alter mouse data on the fly?

What about a software solution?

On Windows, you can intercept the mouse actions with an application, which can be as simple as this AutoHotKey script:

#NoEnv
SetBatchLines -1
Process Priority,,R

BlockInput Mouse        ; user mouse input is ignored during MouseMove
CoordMode Mouse, Screen ; absolute coordinates
SysGet m, Monitor       ; get the screen edges
mLeft += 1, mRight -= 2, mTop += 1, mBottom -= 2
SetMouseDelay -1        ; fastest action

MouseGetPos x0, y0      ; get initial mouse pointer location
SetTimer WatchMouse, 1  ; run the subroutine fast (10..16ms)
Return

WatchMouse:
   MouseGetPos x, y     ; get current mouse position
   x0 += 2*(x0-x), x0 := x0 < mLeft ? mLeft : (x0 > mRight  ? mRight  : x0)
   y0 += 2*(y0-y), y0 := y0 < mTop  ? mTop  : (y0 > mBottom ? mBottom : y0)
   MouseMove x0, y0, 0  ; set new position as old, for the next timer
Return

!z::ExitApp             ; stop the madness; make the script persistent

The same logic can be used to solve the problem in any application programming environment (C++, C#, etc.) which can access the Windows cursor functions.

On Linux, it's as simple as modifying a property for your mouse with xinput, as ben wrote:

xinput set-int-prop "USB Optical Mouse"  "Evdev Axis Inversion" 8 0 1

You'll need to substitute your device name (xinput -list | grep -i 'mouse') for "USB Optical Mouse".

Further questions on this software should be directed to Stack Overflow, our site for programming.


This would be a fairly difficult thing to achieve. Your device would have to behave as both a USB host and a USB peripheral. There may be microcontrollers out there which can do that, but you might end up having to use two, one to be the host, and one the slave.

If you are suggesting something like using a serial mouse, then your job would be much easier to achieve. You'd just need a microcontroller with 2 serial ports, plus two serial interface chips (Like MAX202, or whichever is the newer version).

An even easier option might be to try to write a windows program which would do the inversion.


While this is probably far from the cheapest or most elegant solution, it is one that will give you great flexibility.

An Arduino single board computer can look to a Windows host computer like a Human Interface Device (HID), in other words a mouse. It is not limited to mice however; keyboards and other devices are HID as well.

You could hook a serial mouse directly to the Arduino's serial port or if you prefer to use a USB mouse you could connect it to the Arduino via a USB host shield.

Since you can program the Arduino in C you can translate any sorts of inputs from the mouse into any commands you like going to the PC. You could for example translate a triple click of the right mouse button into a keyboard input command, the sky is the limit.