Page 1 of 1
Key Binding or Forwarding help?
Posted: Tue Aug 30, 2005 1:57 pm
by pyro9219
ok, I got tutorial 4 to work fine with moving the camera, however, as I've seen on another thread here its choppy.
All I really want to do is something like this.
if (e.KeyCode == Keys.W)
{
SendKeys.Send("{UP}");
}
I know the above code works with windows forms.
I've fought with this for about an hour based on the the Tutorial 4 example, and I can't get it to register. I think part of my problem is that SendKeys is located in System.Windows.Forms, and I'm not using a form.
What step do I take now?
Posted: Wed Aug 31, 2005 4:26 am
by shurijo
You have two options.
1) use a windows form (I'm doing this, so I just capture keypress events and handle it through form events, etc.)
2) Write an EventReciever class that implements the Irrlicht IEventReciever and put code similiar to what you posted in that class. You will need to use the event object, but there is a e.Key.KeyCharacter and KeyCode like properties of the keypress event within Irrlicht.
http://irrlicht.sourceforge.net/docu.ne ... mbers.html
I have/had issues when putting Irrlich in my form. Because of the focus - you can't focus the background of the form, so when the background is out of focus (anytime after form_load), the irrlicht event reciever didn't work. So I enabled keypreview on the form, then wrote an event handler for my form to handle the keypress event of the form.
Sorry for the rambling, its late and I'm a bit sleepy. If you need more details, let me know and I can post some example C# or VB.NET code.
Posted: Wed Aug 31, 2005 8:57 am
by pyro9219
I tried using the "move 04" example, and I've even got the copy that was translated into C# as a reference. I'm finding trouble with making that code work the way I want though. I also am not sure how to code things like
[SPACEBAR] or [SHIFT]
In a regular FPS (not sure that I want to make one, but its a great way to learn the graphics engine while having fun :] ), space might be jump, and shift might be crouch ect...
I'm leaving for a plane shortly, and if you want, once I get settled at my destination I'll try and make some code again for sendKey.
I would say my programming knowledge is unbalance, as some area's I'm not very good, and some area's I'm able to do more complicated things. Guess that is what happens when you dont have a whole lot of formal edumacation in programming!
Right now my biggest project is taking my working FPS walkthrough thing I've written, and break it apart into classes and possibly seperate .cs files. I'm still working on this whole OOP concept, as my background isn't OOP.
device.End(me.Ramble, unwantedFlight, true);
;]
Posted: Wed Aug 31, 2005 11:55 pm
by shurijo
In your eventreceiver class, just check for the keypress events of KEY_LSHIFT, KEY_RSHIFT, KEY_SPACE. Are you have a hard time with the eventreceiver or the keypress event?
Key Codes:
http://irrlicht.sourceforge.net/docu/gl ... ml#index_k
A lot of the tutorials have already been translated to C#.
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=7020
Posted: Thu Sep 01, 2005 4:01 am
by pyro9219
Using the C# translation example, this is the code:
class MyEventReceiver : IEventReceiver
{
public bool OnEvent(Irrlicht.Event e)
{
/*
If the key 'W' or 'S' was left up, we get the position of the scene node,
and modify the Y coordinate a little bit. So if you press 'W', the node
moves up, and if you press 'S' it moves down.
*/
if ((node!=null) && (e.Type==EventType.KeyInput) && e.KeyPressedDown)
{
switch(e.KeyCharacter)
{
case 'w':
case 'W':
{
node.Position = new Vector3D(node.Position.X,node.Position.Y+2.0f,node.Position.Z);
return true;
}
case 's':
case 'S':
{
node.Position = new Vector3D(node.Position.X,node.Position.Y-2.0f,node.Position.Z);
return true;
}
}
}
return false;
}
}
what part are you talking about editing? This entire code block seems rather clunky to me for a detection and override.
Posted: Thu Sep 01, 2005 4:10 am
by shurijo
Use e.Key instead of e.KeyCharacter. Key has KeyCodes (like the one I hyperlinked above. It works with all the buttons that are not ascii chars (like F1-F12, shift, control, page up, page down, insert, delete, etc.)
In my eventreciever, I broke it out into 4 functions. The implemented one (which calls the other 3), then one for each event type. KeyPressDown/Up, Mouse, etc. It made managing the switches a bit easier.
Code: Select all
switch(e.Key)
{
case Irrlicht.KeyCode.KEY_KEY_W:
node.Position = new Vector3D(blah);
return true;
break;
case Irrlicht.KeyCode.KEY_KEY_S:
node.Position = new Vector3D(blah);
return true;
break;
case Irrlicht.KeyCode.KEY_SPACE:
//do space here
break;
case Irrlicht.KeyCode.KEY_RSHIFT:
case Irrlicht.KeyCode.KEY_LSHIFT:
//do shift here
break;
}
Posted: Thu Sep 01, 2005 5:07 am
by pyro9219
cool, that worked, however, its contradictor of itself. the node only moves on a certain axis, which isn't updated when mouselook is used. thats why I was just trying to rebind the keys already in use, exactly how they are used.
this is my node data:
node.Position.X,node.Position.Y+2.0f,node.Position.Z
how do I formulate that to be like the basic FPS?
Posted: Thu Sep 01, 2005 11:40 pm
by shurijo
You should look into the
AddCameraSceneNodeFPS.
I haven't messed with it, but its a FPS style camera, so it moves in the direction you are looking, etc. It works different than the camera you are using now.
Posted: Sat Sep 03, 2005 9:39 am
by pyro9219
I am using the FPS camera.
The problem is that the node moves on the X axis from the maps perspective, not from the mouselooks. :/
Posted: Sat Sep 03, 2005 5:04 pm
by shurijo
Oh... I haven't messed with the FPS camera. I think you will have to use the vectors to figure out which way you are looking vs which way to move. I am having to do the same thing using the other camera, but I haven't tackled it yet. :/
Posted: Sat Sep 03, 2005 7:42 pm
by pyro9219
no problem. I still say I want to just be able to do what I originally posted for my directional key bindings. But this is working towards the end solution either way, thanks for your time :]
Re: Key Binding or Forwarding help?
Posted: Mon Jun 20, 2022 7:15 am
by netpipe
can the EKA_MOVE_FORWARD be triggered without the keyboard ? for joysticks
if (CursorKeys[EKA_MOVE_FORWARD])
pos += movedir * timeDiff * MoveSpeed;
maybe irrlicht needs a joystick version with variable movespeed or sensitivity to try
it would need a vertical and horizontal movespeed to make it more user friendly
Re: Key Binding or Forwarding help?
Posted: Mon Jun 20, 2022 10:08 am
by CuteAlien
FPS animator only checks for key events. You'd have to write your own animator for that. Or catch joytick events and pass them back to Irrlicht as key-events.