ManyMouse

BlitzMax Forums/BlitzMax Programming/ManyMouse

There doesn't seem to have been much in the way of interfaces for using ManyMouse - which as the name suggests, allows you to use more than one mouse in a program - hence this post.

I've got a small C interface up and running for use in BlitzMax, as well as using the original routines for initialising the interface.

First, the test program :

SuperStrict

Import "manymouse.c"
Import "macosx_hidmanager.c"
Import "macosx_hidutilities.c"
Import "windows_wminput.c"
Import "linux_evdev.c"
Import "x11_xinput.c"
Import "BlitzMaxManyMouseInterface.c"

Const MANYMOUSE_EVENT_ABSMOTION:Int = 0
Const MANYMOUSE_EVENT_RELMOTION:Int=1
Const MANYMOUSE_EVENT_BUTTON:Int=2
Const MANYMOUSE_EVENT_SCROLL:Int=3
Const MANYMOUSE_EVENT_DISCONNECT:Int=4
Const MANYMOUSE_EVENT_MAX:Int=5

Extern
	Function ManyMouse_Init:Int()
	Function ManyMouse_Quit()
	Function ManyMouse_DeviceName:Byte Ptr(index:Int)
	Function manyMouse_BMInterface_PollEvent:Byte()
	Function manyMouse_BMInterface_ReturnDeviceID:Int()
	Function manyMouse_BMInterface_ReturnItem:Int()
	Function manyMouse_BMInterface_ReturnValue:Int()
	Function manyMouse_BMInterface_ReturnType:Int()
EndExtern

Local numMice:Int
Local loop:Int
Local device:Int
Local eType:Int
Local item:Int
Local value:Int

Graphics 640,480,32

numMice=ManyMouse_Init()

Print "Number Of Mice:"+numMice

For loop=0 To numMice-1
	Print deviceNameToString(loop)
	'Print "Mouse Name : "+ManyMouse_DeviceName(loop)
Next

While Not KeyHit(KEY_ESCAPE)
	Cls
	
	While manyMouse_BMInterface_PollEvent()
		device=manyMouse_BMInterface_ReturnDeviceID()
		eType=manyMouse_BMInterface_ReturnType()
		item=manyMouse_BMInterface_ReturnItem()
		value=manyMouse_BMInterface_ReturnValue()
		Select eType
			Case MANYMOUSE_EVENT_ABSMOTION
									DrawText "Mouse "+device+" absolute motion ",0,0
									If item=0
										DrawText "X:"+value,0,16
									Else
										DrawText "Y:"+value,0,16
									EndIf
			Case MANYMOUSE_EVENT_RELMOTION
									DrawText "Mouse "+device+" relative motion ",0,32
									If item=0
										DrawText "X:"+value,0,48
									Else
										DrawText "Y:"+value,0,48
									EndIf
			
			Case MANYMOUSE_EVENT_BUTTON
									DrawText "A Button has been pressed ("+device+"/"+item+")",0,64
									If value
										DrawText "Down",0,64+16
									Else
										DrawText "Up",0,64+16
									EndIf
									
			Case MANYMOUSE_EVENT_SCROLL
									DrawText "Scroll wheel on mouse "+device,0,128
									If item=0
										DrawText "Vertical",0,128+16
										If value>0 
											DrawText "Up",0,128+32
										Else
											DrawText "Down",0,128+32
										EndIf
									Else
										DrawText "Horizontal",0,128+16
										If value>0
											DrawText "Right",0,128+32
										Else
											DrawText "Left",0,128+32
										EndIf
									EndIf
									
									
		EndSelect
	EndWhile
	
	Flip
EndWhile
ManyMouse_Quit()
End

Function deviceNameToString:String(index:Int)
Local temp:Byte Ptr
Local result:String
Local index2:Int
	
	result=""
	temp=ManyMouse_DeviceName(index)
	index2=0
	While temp[index2]<>0
		result:+Chr$(temp[index2])
		index2:+1
	EndWhile
	
	Return result
EndFunction


And the C interface program :

/*
 *  BlitzMaxManyMouseInterface.h
 *  
 *
 *  Created by Nicholas Kingsley on 31/03/2008.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#include "ManyMouse.h"
#include "stdio.h"
#include "stdlib.h"

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

ManyMouseEvent event;

void manyMouse_BMInterface_Clear(void)
{
	memset(&event,(char) 0,sizeof(event));
}

char manyMouse_BMInterface_PollEvent(void)
{
	if (ManyMouse_PollEvent(&event))
	{
		return TRUE;
	}
	
	return FALSE;
}

int manyMouse_BMInterface_ReturnDeviceID(void)
{
	return event.device;
}

int manyMouse_BMInterface_ReturnItem(void)
{
	return event.item;
}

int manyMouse_BMInterface_ReturnValue(void)
{
	return event.value;
}

int manyMouse_BMInterface_ReturnType(void)
{
	return event.type;
}


ManyMouse works on Windows and Mac (Intel and should work on PPC). It should also work on Linux, but I haven't tried it yet.

ManyMouse itself can only be retrieved using SVN (unfortunately), but is availiable at http://icculus.org/manymouse/

this is awesome, I was looking for this very thing not too long ago!

Nice one. This was discussed here a few times, but nothing much came of it.

I have found a slight modification for the Mac is needed to get the system working, otherwise multiple mice come out as device 0.

In manymouse.c, the ordering of the mouse drivers needs changing to :

static const ManyMouseDriver **mice_drivers[] =
{
    &ManyMouseDriver_xinput,
    &ManyMouseDriver_evdev,
    &ManyMouseDriver_windows,
    &ManyMouseDriver_hidutilities,
    &ManyMouseDriver_hidmanager
};


Whether its due to any of the mice working in PPC mode or something, I dont know - but this order works correct.