Page 1 of 1

Bool Controlling Mouse/Keyboard

Posted: Wed Dec 26, 2007 1:42 pm
by konrad
Control class :

Code: Select all

//! Class Controlling  -------------------------------------------
bool Keys[KEY_KEY_CODES_COUNT];
bool Mouse[EMIE_COUNT];
class _RECControl : public IEventReceiver
{
 public:
   bool OnEvent(const SEvent& event)
   {
     if(event.EventType == irr::EET_KEY_INPUT_EVENT)
     {
       Keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
       return true;
     }
     if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
     {
        Mouse[event.MouseInput.Event]=event.MouseInput.Event;
        return true;
     }
     return false;
   }
};
Engine start:

Code: Select all

//! Engine  -------------------------------------------
 _RECControl _Control;
 IrrlichtDevice* device=createDevice(video::EDT_OPENGL,core::dimension2d<s32>(640,480),32,false,false,false,&_Control);
 video::IVideoDriver* driver=device->getVideoDriver();
 scene::ISceneManager* smgr=device->getSceneManager();
 gui::IGUIEnvironment* guienv=device->getGUIEnvironment();
Int mani:

Code: Select all

//! Main  -------------------------------------------
int mani()
{
   for(int x=0; x<KEY_KEY_CODES_COUNT; x++) { Keys[x]=false; }
   for(int x=0; x<EMIE_COUNT; x++) { Mouse[x]=false; }
// (...)
And use Keys/Mouse bool:

Code: Select all

if(Keys[KEY_ESCAPE]) { break; }
// Other keys codes in Wiki or Documentation
if(Mouse[EMIE_LMOUSE_LEFT_UP]) { break; }
// Other mouse codes in Wiki or Documentation
Enjoy! :D