two Keyboard keys press

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
irado
Posts: 22
Joined: Mon Jun 20, 2005 4:46 pm

two Keyboard keys press

Post 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]
Guest

Post 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
}
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Guest

Post 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.
irado
Posts: 22
Joined: Mon Jun 20, 2005 4:46 pm

Post 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 );
Guest

Post 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.
Guest

Post 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.
Guest

Post by Guest »

besides having changed - > for. I took off the declarations of the class:

CIrrLichtEvent();
virtual ~CIrrLichtEvent();

thank you.
irado
Posts: 22
Joined: Mon Jun 20, 2005 4:46 pm

Post by irado »

besides having changed - > for. I took off the declarations of the class:

CIrrLichtEvent();
virtual ~CIrrLichtEvent();

thank you.
Dodge
Posts: 9
Joined: Fri Aug 05, 2005 7:20 am

Post by Dodge »

which funcion means what?

bool IsKeyDown(int index) == Key is down

bool IsKeyUpDown(int index) == ???

bool IsKeyDownUp(int index) == ???


Pls help me :(
Guest

Post 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
Post Reply