additional mousebuttons (X1 and X2) win32

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
mosics
Posts: 1
Joined: Tue May 15, 2007 12:31 pm

additional mousebuttons (X1 and X2) win32

Post by mosics »

i edited irrlicht 1.3 source to support x1 and x2 mousebuttons.

maybe some other peeps want this feature too. whatever this workaround supports only win32 input at the moment. to support linux, the CIrrDeviceLinux.cpp would need to be changed too. as i am not developing with a linux system right now i did not change it.

the following files must be edited:
IEventReciever.h
CIrrDeviceWin32.cpp

changes in IEventReciever.h:
find the enum EMOUSE_INPUT_EVENT and change it to the following:

Code: Select all

//! Enumeration for all mouse input events
	enum EMOUSE_INPUT_EVENT
	{
		//! Left mouse button was pressed down.
		EMIE_LMOUSE_PRESSED_DOWN = 0,

		//! Right mouse button was pressed down.
		EMIE_RMOUSE_PRESSED_DOWN,

		//! Middle mouse button was pressed down.
		EMIE_MMOUSE_PRESSED_DOWN,

		//! Left mouse button was left up.
		EMIE_LMOUSE_LEFT_UP,

		//! Right mouse button was left up.
		EMIE_RMOUSE_LEFT_UP,

		//! Middle mouse button was left up.
		EMIE_MMOUSE_LEFT_UP,

		//! The mouse cursor changed its position.
		EMIE_MOUSE_MOVED,

		//! The mouse wheel was moved. Use Wheel value in event data to find out
		//! in what direction and how fast.
		EMIE_MOUSE_WHEEL,

		//! X1 mouse button was pressed down.
		EMIE_X1MOUSE_PRESSED_DOWN,

		//! X2 mouse button was pressed down.
		EMIE_X2MOUSE_PRESSED_DOWN,

		//! X1 mouse button was left up.
		EMIE_X1MOUSE_LEFT_UP,

		//! X2 mouse button was left up.
		EMIE_X2MOUSE_LEFT_UP,

		//! No real event. Just for convenience to get number of events
		EMIE_COUNT
	};
changes in IEventReciever.h:
1. find the method LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) and change the defines in the first lines of the method from:

Code: Select all

#ifndef WM_MOUSEWHEEL
	#define WM_MOUSEWHEEL 0x020A
	#endif
	#ifndef WHEEL_DELTA
	#define WHEEL_DELTA 120
	#endif
to:

Code: Select all

	#ifndef WM_MOUSEWHEEL
	#define WM_MOUSEWHEEL 0x020A
	#endif
	#ifndef WHEEL_DELTA
	#define WHEEL_DELTA 120
	#endif
	#ifndef WM_XBUTTONDOWN
	#define WM_XBUTTONDOWN 0x020B
	#endif
	#ifndef WM_XBUTTONUP
	#define WM_XBUTTONUP 0x020C
	#endif
	#ifndef XBUTTON1
	#define XBUTTON1 1
	#endif
	#ifndef XBUTTON2
	#define XBUTTON2 2
	#endif
2. find the switch "switch (message)" wich should be around line 103 after changing the defines and add the following two cases into the switch:

Code: Select all

// X1 und X2 buttons
	case WM_XBUTTONDOWN:
		
		if(HIWORD(wParam)==XBUTTON1)
		{
			ClickCount++;
			SetCapture(hWnd);
			event.EventType = irr::EET_MOUSE_INPUT_EVENT;
			event.MouseInput.Event = irr::EMIE_X1MOUSE_PRESSED_DOWN;
			event.MouseInput.X = (short)LOWORD(lParam);
			event.MouseInput.Y = (short)HIWORD(lParam);
			dev = getDeviceFromHWnd(hWnd);
			if (dev)
				dev->postEventFromUser(event);
			return 0;
		}
		else if(HIWORD(wParam)==XBUTTON2)
		{
			ClickCount++;
			SetCapture(hWnd);
			event.EventType = irr::EET_MOUSE_INPUT_EVENT;
			event.MouseInput.Event = irr::EMIE_X2MOUSE_PRESSED_DOWN;
			event.MouseInput.X = (short)LOWORD(lParam);
			event.MouseInput.Y = (short)HIWORD(lParam);
			dev = getDeviceFromHWnd(hWnd);
			if (dev)
				dev->postEventFromUser(event);
			return 0;
		}
		return 0;


	case WM_XBUTTONUP:

		if(HIWORD(wParam)==XBUTTON1)
		{
			ClickCount--;
			if (ClickCount<1)
			{
				ClickCount=0;
				ReleaseCapture();
			}
			event.EventType = irr::EET_MOUSE_INPUT_EVENT;
			event.MouseInput.Event = irr::EMIE_X1MOUSE_LEFT_UP;
			event.MouseInput.X = (short)LOWORD(lParam);
			event.MouseInput.Y = (short)HIWORD(lParam);
			dev = getDeviceFromHWnd(hWnd);
			if (dev)
				dev->postEventFromUser(event);
			return 0;
		}
		else if(HIWORD(wParam)==XBUTTON2)
		{
			ClickCount--;
			if (ClickCount<1)
			{
				ClickCount=0;
				ReleaseCapture();
			}
			event.EventType = irr::EET_MOUSE_INPUT_EVENT;
			event.MouseInput.Event = irr::EMIE_X2MOUSE_LEFT_UP;
			event.MouseInput.X = (short)LOWORD(lParam);
			event.MouseInput.Y = (short)HIWORD(lParam);
			dev = getDeviceFromHWnd(hWnd);
			if (dev)
				dev->postEventFromUser(event);
			return 0;
		}
		return 0;
		
		// X1 und X2 buttons
recompile the irrlicht.dll and reference the new lib and dll in your project to get the X1 and X2 mousebutton support.

if somebody found out how to get this support with linux please post it here.

regards mosics

PS: i read somewhere about different keycodes with older win32 versions. this workaround works with winxp professional sp2. if this workaround works with older win32 versions too, pleae post it here, thx
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Very nice, I'm going to add this to IRRspintz, thanks.
Image
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

With more buttons it may be better imo to change the MouseInput a little bit so the events are "mouseup" or "mousedown" and add a new attribute containing the mouse button's number?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I posted similar code a while back... http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=16730
With more buttons it may be better imo to change the MouseInput a little bit so the events are "mouseup" or "mousedown" and add a new attribute containing the mouse button's number?
Yeah, but using the new member would break source compatibility with existing applications.

Travis
Post Reply