bool keys[]

A forum to store posts deemed exceptionally wise and useful
Beam

Post by Beam »

Salutes

Ok I do this right after main starts:

CIrrLichtEvent * keyHandler;
keyHandler->Init();

If I just create it (CIrrLichtEvent keyHandler; = no pointer) i get unresolved external symbol.

I use pointer for now, and it compiles, but it doesnt work. Do I need to run something each frame? Simply typing this in the loop do not work:

if(keyHandler->IsKeyDown(KEY_KEY_W))
players[0]->gold+=50;

I must have missed something... Plz help any1. It also warns me about keyHandler not being initialized. But it is right?
Beam
Guest

Re: to use multi-key and mouse-button

Post by Guest »

lifetree wrote: GOOD LUCK!
That is probably all nice and working code, but how do I use it the loop? Tried checking for IsKeyDown but that didn't work.
dopamine
Posts: 3
Joined: Fri Mar 25, 2005 6:10 pm
Location: Poland

Post by dopamine »

Try to implement a method like below
//-------------------------------------
void CIrrLichtEvent::ProcessInput()
{
if (IsKeyDown(KEY_KEY_W))
{
actions...
}

if (IsKeyDown(KEY_KEY_A))
{
actions...
}
...
}
//-------------------------------------
Then in the Irrlicht main loop call it
to handle your events. For example:
...
while(device->run())
if (device->isWindowActive())
{
irrEventRec.ProcessInput();
...
mike (not a member)

i found something useful

Post by mike (not a member) »

ok oddly enough i had a problem where i'd press right and the thing would perform as expected.. btw im using the first method mentioned in this post. when i pressed left or up it did nothing. i loaded up my debugger and put a watch on event.KeyInput.Key and lo and behold it turns out that the event handler in the engine reads my keyboard's left arrow key as KEY_KEY_A. if you're having problems like this i suggest you use a debugger to watch te event.KeyInput.Key variable to see what your keys on your keyboard are actuall y doing in the engine.

hope this helps someone. see ya
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Do you have another kind of keyboard than QWERTY/AZERTY ?
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
GameDude
Posts: 498
Joined: Thu May 24, 2007 12:24 am

Post by GameDude »

This is a good start to learning the key input of the Irrlicht
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post by dudMaN »

Thanks, kaless!!

awesome tutorial thing, and finally my key input works :D but now, its always returning true, which means i cant send input to the camera :(

does this mean i need to do

//OnEvent
if(event.EventType == irr::EET_KEY_INPUT_EVENT
&& event.KeyInput.Key != KEY_UP && event.KeyInput.Key != KEY_DOWN && event.KeyInput.Key != KEY_LEFT && event.KeyInput.Key != KEY_RIGHT){
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return true;
}

?

Thanks!

EDIT: i can probably just do "return false;" instead of "return true;" so the camera cares too.

-dudMan
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Boogle wrote:Hehe, not in C++! It happily references as far outside of your array as you want.
Wtf thats certainly not true... Accessing outside of the array bounds would yeild a memory access error.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

That is true. The only problems that may arise are due to your OS. If C++ would restrict the access when out-of-bounds you'd raise an exception, not a segfault.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Goodpoint
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
sosssego
Posts: 2
Joined: Wed Mar 17, 2010 12:55 am

Post by sosssego »

When i used it with OpenGL and GLut, dont using Irrlicht i used 2 functions to "receive" the event.
one for KeyDown, and another to KeyUp, so i dont need to run false for all keys all the time.
And glutIgnoreKeyRepeat(true); so i dont run the event when nothing was changed, if you press a key and dont release it, the KeyUp will be called 1 time, all that you need is check for your key, if it is set up or down in your bool key[] array.

There is an way to do that in Irrlicht?
There is keyup(), keydown(), and glutIgnoreKeyRepeat(true) like functions?

Ty

sosssego
Post Reply