Page 1 of 1

two Keyboard keys press

Posted: Thu Jul 14, 2005 5:28 pm
by irado
how I can make so that instructions of one uses a keyboard key A that this being press, continues to be executed one another keyboard key B after to have been press? I tested the function event.KeyInput.PressDown in many ways , but it stops the execution of the instructions of the keyboard key A.[/b]

Posted: Thu Jul 14, 2005 7:14 pm
by Guest
It should be this way if I'm not mistakened:

Code: Select all

if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.Event == KEY_KEY_A &&  event.KeyInput.Event == KEY_KEY_B)
{
       //whatever you want to happen goes here
}

Posted: Thu Jul 14, 2005 7:26 pm
by bitplane

Posted: Fri Jul 15, 2005 9:32 am
by Guest
It should be this way if I'm not mistakened:
Please. You're giving Guest a bad name.
That expression can never work. A single variable can never have two values at the same time.

Irado: bitplane is right. That thread explains how you can go from events (which are keypresses/releases, i.o.w. changes) to keystates.

Posted: Mon Jul 18, 2005 2:06 pm
by irado
I search the keystates in the irrlicht but i don't find.

I am trying to use the class, but this saying the error message:
base operand of '->' has non-pointer type 'CIrrLichtEvent'

in the line:
recebe->Init();

this is the class. --------------------------------------------------------------

class CIrrLichtEvent : public IEventReceiver
{
public:
bool m_key_buf[256];
bool m_key_buf_old[256];

public:
CIrrLichtEvent();
virtual ~CIrrLichtEvent();

void Init()
{
bool keys[irr::KEY_KEY_CODES_COUNT] ;
//initialization
for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;

memset(m_key_buf, 0, 256);
memset(m_key_buf_old, 0, 256);
}


virtual bool OnEvent(SEvent event)
{
if (event.EventType)
{
if (EET_KEY_INPUT_EVENT)
{
m_key_buf_old[event.KeyInput.Key] = m_key_buf[event.KeyInput.Key];
m_key_buf[event.KeyInput.Key] = event.KeyInput.PressedDown;
}
}


return true;
}

bool IsKeyDown(int index)
{
return m_key_buf[index];
}

bool IsKeyUpDown(int index)
{
return (m_key_buf[index] && !m_key_buf_old[index]);
}

bool IsKeyDownUp(int index)
{
return (!m_key_buf[index] && m_key_buf_old[index]);
}

};

int main()
{ //main

CIrrLichtEvent recebe;
recebe->Init();

IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480),
16, false, false, false, &recebe );

Posted: Tue Jul 19, 2005 11:04 am
by Guest
That's because you've declared recebe as an object, not as a pointer.

Simply replace -> with . and you're ready to go.

Posted: Tue Jul 19, 2005 11:06 am
by Guest
PS: it's an event receiver, so that class name is not a good choice. It's probably going to cause confusion later on.

Posted: Tue Jul 19, 2005 1:11 pm
by Guest
besides having changed - > for. I took off the declarations of the class:

CIrrLichtEvent();
virtual ~CIrrLichtEvent();

thank you.

Posted: Tue Jul 19, 2005 1:13 pm
by irado
besides having changed - > for. I took off the declarations of the class:

CIrrLichtEvent();
virtual ~CIrrLichtEvent();

thank you.

Posted: Fri Aug 05, 2005 4:44 pm
by Dodge
which funcion means what?

bool IsKeyDown(int index) == Key is down

bool IsKeyUpDown(int index) == ???

bool IsKeyDownUp(int index) == ???


Pls help me :(

Posted: Fri Aug 05, 2005 6:28 pm
by Guest
Those two functions don't work as they should.

They are only supposed to be true when the key is toggled, but the old status is not reset except when the key is toggled.
One way to fix that is to modify them by copying the new key state to the old key state before returning the result of the comparison.

Or you can look at some improved code on this thread:
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=6159