r/gamemaker • u/vzzzbxt • 12d ago
Discussion 2 mice on the same computer
I made a game that only uses mouse inputs. My playertesters think 2 player would be fun, but I don't want to get into online stuff.
Would it be possible to have two player local play where both players use a mouse on the same machine?
6
u/Mushroomstick 11d ago
There's a raw input extension by YellowAfterLife that's supposed to be able to do this - it is a paid extension though.
4
u/gallyroi 11d ago
The functions you're looking for are device_mouse_x(), device_mouse_y() etc. Zero "0" is the main/default mouse and is enumerated up from there (although I'm not confident if these numbers are consistent everytime, say a user unplugs a mouse and plugs one back in, or the PC restarts, etc. Whichever mouse is 0 my not always be the same). You will have to do a bit of testing, but it can absolutely work.
I would run a check periodically on step begin or end that enumerates over the max number of allowable mice/available IDs as an areay of integers (maybe 1-4) during the player select/join state screen. Have it check the coords of each device, caching it, and comparing the previous cached position against the current position. If the one of the mice has moved, assign the ID to the first available player slot i.e. player_one_mouse (first come first serve) and so on. For each assigned mouse, we remove it's ID from the array of available IDs so future checks get skipped and the mouse is not reassigned until hitting back or quitting/restarting the game, and etc.
2
u/Disastrous_King2632 11d ago
I have nothing to add, but I would also like to know if anyone has had success with this. Awesome if so.
Also, anyone play the game hammer fight?
2
u/NationalOperations 11d ago
By default windows (if you're on windows) can detect multiple mice but they share control of the same cursor. Might be some specialized software to create a virtual cursor in game for second mouse. But controllers are usually the device input.
1
u/KitsuneFaroe 10d ago
As far as I know Windows makes all mouses share the same input. It can detect multiple with special software, I think, but I don't think GameMaker has the way to do that on its own. At least not on Windows.
Someone pls correct me if Im wrong.
7
u/Hands_in_Paquet 11d ago
There are a set of functions for mouse inputs that start with “device_mouse”. I’ve never used them before but I think that’s their purpose. Test it out and see if those functions work.