how would i make receiver.IsKeyDown , so that it can only be pressed once? if you get me..because when i do receiver.IsKeyDown(KEY_KEY_W), pressing the W key is like pressing it 10+ times even when i just pressed it once.
I know with GetAsyncKeyState you can do:
// Create a key state that contains all the possible keys.
bool key_state[irr::KEY_KEY_CODES_COUNT];
...
// Set all the values in the key state to false.
memset((void*)key_state, 0, sizeof(bool) * irr::KEY_KEY_CODES_COUNT);
...
bool CGameEventReceiver::OnEvent(const SEvent& event)
{
switch (event.EventType)
{
case irr::EET_KEY_INPUT_EVENT:
{
// Alter our key state. If the key is pressed, it sets the state to true, else if it is released, it will be set to false.
key_state[event.KeyInput.Key] = event.KeyInput.PressedDown;
}
}
}
...
// Check and see if the A key is pressed.
if (key_state[irr::KEY_KEY_A]) doStuff();
class MyEventReceiver: public IEventReceiver {
public:
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event) {
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const {
return KeyIsDown[keyCode];
}
MyEventReceiver() {
for (u32 i = 0; i < KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
Thnak you very much guys for the information you posted..
It really helps me a lot...
Newbie here seeking for Knowledge and friends too...
Godspeed,,,how to deal with depression