How do you gather mouse button clicks and keyboard state?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
ScopeCoder

How do you gather mouse button clicks and keyboard state?

Post by ScopeCoder »

Hi,

Anyoen know how to determine when the mouse button has been clicked(And which one) and how to check if a certain key is being pressed using irrlicht?
Is it even possible?
Guest

Post by Guest »

yes its possible, please use the search function to get information about how to do that :) its been discussed very often
AticAtac
Posts: 29
Joined: Mon Mar 22, 2004 2:46 pm
Location: Germany

Post by AticAtac »

Just an example but should give you the idea how to do it :

Code: Select all

//------------------------------------------------------------------------------
class cEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent ev)
	{
		std::string sevent="";
		int lmb=0, rmb=0;
		EKEY_CODE key_down=EKEY_CODE(0);
		EKEY_CODE key_up=EKEY_CODE(0);
		wchar_t key = 0;

		if (ev.EventType == EET_MOUSE_INPUT_EVENT)
		{			
			if (ev.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) lmb = 1;
			else if (ev.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) lmb = 2;
			else lmb = 0;
			if (ev.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) rmb = 1;
			else if (ev.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) rmb = 2;
			else rmb = 0;			
		} 
		
		if (ev.EventType == EET_KEY_INPUT_EVENT)
		{
			if (ev.KeyInput.PressedDown)
				key_down = ev.KeyInput.Key;
			else			
				key_up = ev.KeyInput.Key;
			key = ev.KeyInput.Char;
		}
		
		if (lmb != 0 || rmb != 0 || key_down != EKEY_CODE(0) || key_up != EKEY_CODE(0))
				g_lastevt = g_guiman->ProcessEvent(ev.MouseInput.X, ev.MouseInput.Y, lmb, rmb, key_down, key_up, key);

		bool b = true;		
		return b;
	}

};
Post Reply