Multiple Mice in Windows using Raw Input

Raw Input is a Microsoft API that provides applications a way to accept raw input from any HID, including the keyboard and mouse. Prior to Windows XP, Microsoft supported using multiple mice independently with DirectX, however this method of using multiple mice was removed in Windows XP and newer. The new alternative is to use Raw Input, or Raw Mouse. The primary goal was to support multiple mice and lightguns in MAME, the Multiple Arcade Machine Emulator, but in the process a generic API was created that can be used in any application. This page provides source code and other information on using Raw Input for the following purposes:

Multiple mice in Windows XP
Multiple mice in Windows Vista
Multiple mice in Windows 10
Multiple relative input devices such as lightguns
Multiple keyboards


Sample Raw Input Code

NOTE: These will only run properly under Windows XP or newer.
My raw mouse api: Here are C source files that you can include in your own C or C++ programs to make using raw mouse very easy. Also included is a demo that shows the features of the package. This is meant to be useful if you are trying to use raw input for your own applications. Compiling instructions are included in the .c file using either Gcc/Mingw or Visual C++. C# version of rawmouse  Thanks to Peter Brumblay, rawinput has been ported to C#! Here are the source files and binaries (dll and demo exe). Visual Studio .net 2003 project files are included. You will need the .net runtimes and Windows XP (or newer) to run these programs. Building them may (or may not) require that you download the Microsoft Platform SDK (see links above).

Here is a minimal Raw Input program written in the C programming language. It displays the number of rawinput devices on your machine. It is a good program to use when getting your rawinput programming environment set up. Compiling instructions are included in the .c file using either Gcc/Mingw or Visual C++.
PacManFan's program (translated to C from the original C++). Displays the movements for all of the mice on the screen. When you run the program, pay attention to the first value (hDevice) - it identifies which mouse the information represents. I missed it the first time I ran it. It displays A LOT of info about the mice, which is very useful for figuring out how to interpret different devices (it was great for figuring out the lightgun). Compiling instructions are included in the .c file using either Gcc/Mingw or Visual C++.
(Visual C++ Workspace) This is a useful program that lists all of the raw input devices on your computer.
Mame Analog+ Raw Mouse source code (version 1) Here are my source code changes that make use of raw mouse in Windows XP. It supports multiple mice with buttons, and also lightguns under Windows XP. They should be applied to the MameAnalog+ version 74 source code.


Microsoft Platform SDK This package contains the headers & libraries needed to compile raw input stuff with visual c++ 6.0. You don't actually need all that stuff, just a few files.
Raw Input on MSDN Combined with some working code samples, this is a good reference about what Raw Input offers.
Japanese Raw Input source This is what finally got me successfully compiling raw input stuff. (Translated to english thanks to


Converting libraries from Microsoft Platform SDK to MinGW/GCC:
I couldn't believe it, but MinGW was able to use the Microsoft Platform SDK libraries, but it required some work on my part. Let me first admit that I never thought this would work, but my will was strong, and it turned out to be easy. First, I ran a program called, "reimp" (part of MinGW tools) on the MS Platform SDK "user32.lib" file. Reimp created my "libuser32.a". I replaced "libuser32.a" in my existing MinGW lib directory. Next, I moved the WinUser.h file into my MinGW include folder. I ran into 2 problems:

1) When I tried to include "winuser.h" into my programs, I got some compiler errors from "winuser.h" itself, so I made some very minor changes to the .h that might have been a little bit sketchy. With a few small changes, it compiled successfully.

2) Next, when I tried access certain features from the old version of "winuser.h" from existing programs (namely the existing Mame source), I got compiler errors again. I was able to copy lines from the old "winuser.h" into the new one to get it to work. Here's a specific example:
When compiling mame with the new winuser stuff for MinGW/GCC I was getting a compiler error: "GetLastError undeclared" (or something like that). I added a GetLastError line to the WinUser.h file, and wouldn't you know it? Mame compiled and ran without any noticeable problems! Now I aught to be able to freely add rawmouse code into Mame and compile it and test it.

The bottom line is that some functionality from any converted libraries is probably missing, and will somehow need to be added if you want to access more than what Mame and my programs use.

RDP_MOU (Terminal services devices)
When raw input enumerates mice and keyboards, it enumerates all the mice, keyboards, and joysticks that I have connected to my system. In addition, it enumerates one extra root device (a mouse) identified as "RDP_MOU". It also enumerates a similar keyboard device. These appear to be the Windows remote mouse and keyboard that are accessed with Terminal Services.

Note to self
Upload buffered read stuff for dual mice. Also for duel mice.

NOTE FOR MAME USERS: The Mame modifications explained here have been merged with the official version of Mame. If you are looking to use multiple trackballs, spinners, and lightguns in Mame using Windows XP then look no further than the official Mame page!

SUBNOTE FOR MAME USERS: Mame Analog+ supports Raw Mouse for some older versions of Mame, however it hasn't been updated in a while. AdvanceMame also supports multiple mice using RawInput.

This has become an issue because some of the members of Build Your Own Arcade Controls message board and I are stuck running crappy old Windows 95/98/ME on our Mame cabinets if we want to use multiple trackballs to play such great games as Marble Madness (2 trackballs), Rampart (3 trackballs), or Atari Soccer (4 trackballs). Lightguns are affected by the same problem, because Windows treats lightguns as mice (for the most part).


RawMouse is now available in the official build of Mame! Woohoo!

Derrick Renaud has reworked the code from this site so that it fits cleanly into the official version of Mame. Multiple mice can now be enjoyed without using unofficial Mame versions. This is great news - The ultimate goal of this page has been accomplished. Read the announcement here. Get Mame from here.

Fixed a bug introduced when compiling with the latest MS compilers (MS VC++ Express 2005 in particular).

It looks like the wm_input messages are not reporting the relative mode flag anymore (raw->data.mouse.usFlags & MOUSE_MOVE_RELATIVE). It looks to me as though I'm supposed to assume it's a relative device unless wm_input reports otherwise. That's an easy fix. In raw_mouse.c, in the function init_raw_mouse, initialize is_absolute to 0 for the sys_mouse and currentmouse. I have updated the source code (raw_mouse.c and raw_mouse_test.exe) with the small addition. While I was at it, I initialized is_virtual_desktop to 0.

Rag Doll Kung Fu has been released on Steam.

Rag Doll Kung Fu, an exciting new game that uses the raw input code from this site, is now available for download through Steam! Enjoy playing with as many as 8 players using multiple mice! Find out more here.

MinGW now supports rawinput!

There is no longer a need for my winuser header/lib, because MinGW has them built-in. I updated the source files to work with the new MinGW from the Mame website.

Rawmouse C# Port!

Peter Brumblay has ported the rawmouse code to C#! It consists of a dll and a demo program. As of right now, it will not support "absolute" devices such as lightguns and touchscreens. You can email him at:

See the downloads section for the files.

Made a small change to yesterday's raw mouse api (raw_mouse.h, raw_mouse.c, and raw_mouse_test.c) update. I made OS detection a part of init_raw_mouse instead of making a separate function.

Include RawMouse in an application without crashing under unsupported versions of Windows!
I have updated my raw mouse api (raw_mouse.h, raw_mouse.c). An exe will now run on versions of Windows that support raw input and versions that don't! The test program (raw_mouse_test.c) will now detect whether rawinput is available and exits gracefully instead of crashing. With this code, Mame Analog+ won't need 2 separate builds (one for Windows9x and one for Windows XP and newer) because it can detect which method of mouse input is available and choose accordingly.

The code was very kindly sent to me by Mark Healey and Alex Evens at Lionhead Studios. Mark emailed me awhile back because he's using my rawmouse code for his up-and-coming game, "Rag Doll Kung Fu". He has added support for up to 8 players using separate mice on a single machine. Sounds like a real mess! The game looks really incredible. You can check out the press release here, or go to the game's main website at

(2006 UPDATE: StarRoms is no longer providing the following service).

Great news! Atari (now owned by Infrogrames) has agreed to make their old arcade game roms available for purchase for use with Mame. This means that you can purchase copies of many of the multiple mouse Mame roms to play in your home!

Some of the games include Atari Football (4 trackballs), Atari Soccer (4 trackballs), Rampart (3 trackballs), Blasteroids (2 spinners), Marble Madness (2 trackballs), Warlords (4 paddles), and many more.

Most of these games have been available in the past in such packages as the Digital Eclipse Arcade Collections, but this is different because it is specifically being sold to be used with whichever emulator you choose, such as Mame: Analog+ XP with support for multiple trackballs!

Hooray! Multiple mouse and lightgun support is now available for users of Windows XP in Mame: Analog+.


- Multiple Mouse Support (mameanalog -mouse -multimousexp soccer)
- Multiple Lightgun Support (mameanalog -lightgun -multimousexp policetr)
- -switchmouse, -switchaxes, -onemouse, -splitmouse, -resetmouse all work
- Support for 3 mouse buttons
- In Windowed mode, I attempt to acquire the mouse, but it's still possible to break out using
a small window, quick button presses, and fast fingers

Updated the source to be compatible with Mame74. A few small changes, and it's ready to rock.

Raw lightgun support for Mame! The raw mouse Mame code has been updated to work with one lightgun and should work with multiple lightguns. I can't test multiple because I only have one Act Labs PC USB Light gun. If it doesn't happen to work it'll be easy to fix.

Raw mouse buttons for Mame! Finally something worth mentioning!

Multiple raw mice in Mame! I created an interface raw_mouse.h and raw_mouse.c which can be included into c program very easily. I hacked the MameAnalog+ code (quick and dirty) to make use of this new raw_mouse interface, and it wasn't long before I got 4 mice to work in Mame using WindowsXP.

2003-9-11 11:40pm
I updated the MinGW/GCC lib and header files for "winuser.h" with a version that will successfully compile a runable Mame.

2003-9-11 5pm-ish
I managed to convert the raw input header and library files from the Microsoft Platform SDK (namely WinUser.dll/user32.lib/winuser.h) into something that MinGW/GCC can use. I converted PacManFan's program from C++ to C so that it will compile with the Mame MinGW compiler package (plus the updated winuser stuff) instead of Visual C++.

2003-9-11 Noon-ish
PacManFan sent me his C++ demo which displays mouse data for multiple mice via rawmouse. Thanks Steve!

I gotta love those flowered Barbie USB mice (99 cents apiece!!!) I wish I knew how useful they would be when I got them. Whoda thought I'd regret not buying more of them - I figured 20 would be enough.

One comment

Leave a Reply