Multiple Key Board Keys
Multiple Key Board Keys
Hmm, Im trying to make a custom camera scene node and I think I found a prob with the engine...
Is there anyway to take input from two keys like W & A? From what I can see the engine only allows one key to be pressed at a time when using the IEvenetReceiver class.
Is there anyway to take input from two keys like W & A? From what I can see the engine only allows one key to be pressed at a time when using the IEvenetReceiver class.
-
- Posts: 340
- Joined: Wed Sep 28, 2005 4:38 pm
- Location: Canada, Eh!
re:
Here's an event receiver class that I use, every time a key is pressed, a key in an array gets set to true, and you can handle the keypresses in the main loop:
CEventReceiver.h
CEventReceiver.cpp
In your main loop, handle keypresses like so:
[/code]
CEventReceiver.h
Code: Select all
// Event Receiver Class
class CEventReceiver : public IEventReceiver
{
public:
CEventReceiver();
virtual bool OnEvent(SEvent Event);
bool getKeyState(EKEY_CODE key);
private:
bool keys[KEY_KEY_CODES_COUNT];
};
Code: Select all
// Include headers
#include "include/CEventReceiver.h"
// Constructor
CEventReceiver::CEventReceiver()
{
for (int i = 0; i < KEY_KEY_CODES_COUNT; i++)
{
keys[i] = false;
}
}
// Event handler function
bool CEventReceiver::OnEvent(SEvent Event)
{
if (Event.EventType == EET_KEY_INPUT_EVENT)
{
keys[Event.KeyInput.Key] = Event.KeyInput.PressedDown;
}
return true;
}
// Get key state
bool CEventReceiver::getKeyState(EKEY_CODE key)
{
return keys[key];
}
Code: Select all
if (EventReceiver->getKeyState(KEY_KEY_A))
{
// Do something
}
Yes.Is there anyway to take input from two keys like W & A?
Code: Select all
if (EventReceiver->getKeyState(KEY_KEY_A && KEY_KEY_W))
{
// Do something
}
If it exists in the real world, it can be created in 3d
Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
-
- Posts: 340
- Joined: Wed Sep 28, 2005 4:38 pm
- Location: Canada, Eh!
Actually, no it doesn't, for me anyways. I'm gonna take a look at that sometime later. If you want, maybe try this:However, does your FPS camera work?
Code: Select all
// Event handler function
bool CEventReceiver::OnEvent(SEvent Event)
{
if (Event.EventType == EET_KEY_INPUT_EVENT)
{
keys[Event.KeyInput.Key] = Event.KeyInput.PressedDown;
return true;
}
return false;
}
-
- Posts: 340
- Joined: Wed Sep 28, 2005 4:38 pm
- Location: Canada, Eh!
re:
No, you'd have to do basically the same thing I did with the keyboard, except make an array of mouse keys, and every time a mouse button is down, set a key in the array to true, every time it is lifted, set the array key back to false. If you want to do that, you should make the method return a position2d<> with the coords of the last mouse click.
try http://irrlicht.sourceforge.net/phpBB2/ ... t=key#4525
it may help
it may help