Irrlicht.IrrEvent.keyStates
IrrLib 1.X
Irrlicht.IrrEvent.keyStates — This public array of bool values is used to determine if a key was hit
Description
bool Irrlicht.IrrEvent.keyStates
(
)
Parameters
None
Return Values
Returns true if the key was hit
Examples
Example #1 This will move a sphere depending on what hit you hit.
#include <iostream> #include "IrrLib.h" #include <irrlicht.h> using namespace std; using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui; int main(){ IrrLib Irrlicht(5, 640, 480, 16, false, true, false); Irr3DObjColor col1; Irr3DObjColor col2; int vel = 1; int nHits; //int nTimes = 0; //Color 1 col1.a = 255; col1.r = 0; col1.g = 255; col1.b = 5; //color 2 col2.a = 255; col2.r = 0; col2.g = 255; col2.b = 255; //Pos 1 Irr3DPos pos1; Irr3DPos pos2, pos3; pos3.x = -200; pos3.y = 0; pos3.z = 0; pos2.x = 200; pos2.y = 0; pos2.z = 0; pos1.x = 0; pos1.y = 0; pos1.z = 0; Irr3DObj obj1; obj1->setColor(col1); obj1->setMesh("sphere.3ds"); Irr3DObj obj2, obj3; obj3->setMesh("cube.3ds"); obj2->setMesh("cube.3ds"); obj2->setColor(col2); obj3->setColor(col2); obj1->addToScene(); obj2->addToScene(); obj3->addToScene(); Irrlicht.AddFPSCam(); obj2->Move(pos2); obj3->Move(pos3); while (Irrlicht.DeviceIsRunning()) if (Irrlicht.IsActiveWindow()) { if (Irrlicht.IrrEvent.keyStates[KEY_KEY_W]){ Irrlicht.IrrEvent.keyStates[KEY_KEY_W] = false; pos1.x = pos1.x + 10; obj1->Move(pos1); } if (Irrlicht.IrrEvent.keyStates[KEY_KEY_S]){ Irrlicht.IrrEvent.keyStates[KEY_KEY_S] = false; pos1.x = pos1.x - 10; obj1->Move(pos1); } Irrlicht.BeginScene(Irrlicht.Color.RED); Irrlicht.DrawAll(); Irrlicht.EndScene(); nHits = 0; } Irrlicht.EndIrrlicht(); return 0; }
You can find the meshes used in this example here.
Notes
This will change in version 2.
Also, please do note you need to set it to false, else your if test will be ran multiple times.
User Contributed Notes
Irrlicht.IrrEvent.keyStates
Irrlicht.IrrEvent.keyStates
