Multiple-key input?
Multiple-key input?
Hey. I hope this q hasn't been posted before, but I couldn't find it searching so..
Currently I have, through looking at the example, setup a scene with a terrain and a model for the player to control. I've gotten the player to collide with the terrain,the camera to follow the player and the player to move according to keyboard input.
The problem is that it only responds to one key at a time, unless two keys were pressed simultaneously (i.e. pressing A turns left, but pressing W while holding down A stops turning and only moves forward. But pressing both simultaneously would move the player forward at the same time as turning him.)
Does anyone have a suggestion on how to allow the player to turn while still moving forward without having to press the two keys down simultaneously?
Currently I have, through looking at the example, setup a scene with a terrain and a model for the player to control. I've gotten the player to collide with the terrain,the camera to follow the player and the player to move according to keyboard input.
The problem is that it only responds to one key at a time, unless two keys were pressed simultaneously (i.e. pressing A turns left, but pressing W while holding down A stops turning and only moves forward. But pressing both simultaneously would move the player forward at the same time as turning him.)
Does anyone have a suggestion on how to allow the player to turn while still moving forward without having to press the two keys down simultaneously?
Lordi in Eurovision Song Contest 06? Now we're getting somewhere!
-
- Posts: 30
- Joined: Wed Mar 15, 2006 7:42 pm
- Location: http://cube3.helpmy.net
You would typically hold the keys in a buffer aray of like say 256 elements, which contains boolean's (pressed or not pressed).
The element index, corresponds to the keycode. I am sure there's something posted on this.
The element index, corresponds to the keycode. I am sure there's something posted on this.
Platform 3D Engine using Irrlicht.NET
http://cube3.helpmy.net
http://cube3.helpmy.net
-
- Posts: 279
- Joined: Fri Dec 24, 2004 6:37 pm
I think you are making an if condition like this:
if Left Key then
Move left
elseif Right key then
Move Right
elseif Up key then
Move Forward
elseif Down key then
Move backward
end if
if you have a condition like this make it like this:
if Left Key then
Move left
end if
if Right key then
Move Right
end if
if Up key then
Move Forward
end if
if Down key then
Move backward
end if
if Left Key then
Move left
elseif Right key then
Move Right
elseif Up key then
Move Forward
elseif Down key then
Move backward
end if
if you have a condition like this make it like this:
if Left Key then
Move left
end if
if Right key then
Move Right
end if
if Up key then
Move Forward
end if
if Down key then
Move backward
end if
Thanks for replying!
The problem is that only one key is recieved through the parameter of the event-handler method. So with your method, RapchikProgrammer, only one clause is entered and the same behaviour happens.
Cube3, for the same reason, I'm unsure how that keyarray would help, seeing as I can't find out if a key is released, only pressed down and would have to reset the array on intervals. And if that interval was too short, the same behaviour would appear, but too long and the action would continue til after the key was released.
The problem is that only one key is recieved through the parameter of the event-handler method. So with your method, RapchikProgrammer, only one clause is entered and the same behaviour happens.
Cube3, for the same reason, I'm unsure how that keyarray would help, seeing as I can't find out if a key is released, only pressed down and would have to reset the array on intervals. And if that interval was too short, the same behaviour would appear, but too long and the action would continue til after the key was released.
Lordi in Eurovision Song Contest 06? Now we're getting somewhere!
-
- Posts: 30
- Joined: Wed Mar 15, 2006 7:42 pm
- Location: http://cube3.helpmy.net
If you are willing to do your own implementation instead of irrlicht's, you could take a look at http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=12301
Platform 3D Engine using Irrlicht.NET
http://cube3.helpmy.net
http://cube3.helpmy.net
-
- Posts: 5
- Joined: Fri Nov 03, 2006 8:16 pm
-
- Posts: 30
- Joined: Wed Mar 15, 2006 7:42 pm
- Location: http://cube3.helpmy.net
Seems Like I didn't want a dependency to Managed Direct Input.
Edit:
Seem Like you didn't want it either after all.
Edit:
Seem Like you didn't want it either after all.
Platform 3D Engine using Irrlicht.NET
http://cube3.helpmy.net
http://cube3.helpmy.net
I added this code to my project and it kept generating exceptions inside Irrlicht (and not processing my keys), which I have not been able trace it because even if I alt-tab, the app still has my mouse locked to the center of the screen. Admittedly, I haven't tried to work around that as yet, I've been busier trying to understand how the KeyboardListener class works.Cube3 wrote:If you are willing to do your own implementation instead of irrlicht's, you could take a look at http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=12301
I don't have that problem. Just have your event handler set boolean variables and then check them in your rendering loop. Make sure to use if(){} and not if(){}else if(){} . You are probably calling your actions from the event handler, which will make them be one action per keypress or one action per entrance to the even handler. Setting up which action to call in event handler then actually calling in render loop works, and it's easier than monkeying with directx directly.Hellfish wrote:The problem is that it only responds to one key at a time, unless two keys were pressed simultaneously (i.e. pressing A turns left, but pressing W while holding down A stops turning and only moves forward.
Code: Select all
bool moveForward = false;
bool rotating = false;
float rotateBy = 0.0f;
...
while(device->run() && !ExitFlag)
if (device->isWindowActive())
{
driver->beginScene(true, true, 0 );
if(moveForward)
{
moveF(node);
}
if(rotating)
{
rotate(node, rotateBy);
}
smgr->drawAll();
env->drawAll();
driver->endScene();
}
Keypress is event.KeyInput.PressedDown, so release is !event.KeyInput.PressedDownHellfish wrote:Cube3, for the same reason, I'm unsure how that keyarray would help, seeing as I can't find out if a key is released, only pressed down and would have to reset the array on intervals.
Code: Select all
bool OnEvent(SEvent event)
{
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
{
if(event.KeyInput.PressedDown)
{
switch (event.KeyInput.Key)
{
case irr::KEY_SHIFT:
rotating = true;
break;
case irr::KEY_KEY_W:
moveForward = true;
break;
}
else /* key released */
{
switch (event.KeyInput.Key)
{
case irr::KEY_SHIFT:
rotating = false;
break;
case irr::KEY_KEY_W:
moveForward = false;
break;
}
}
}