Key Binding or Forwarding help?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
pyro9219
Posts: 14
Joined: Mon Aug 29, 2005 2:10 pm
Location: Portland, Oregon

Key Binding or Forwarding help?

Post 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?
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post 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.
pyro9219
Posts: 14
Joined: Mon Aug 29, 2005 2:10 pm
Location: Portland, Oregon

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

;]
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post 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
pyro9219
Posts: 14
Joined: Mon Aug 29, 2005 2:10 pm
Location: Portland, Oregon

Post 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.
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post 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;
}
pyro9219
Posts: 14
Joined: Mon Aug 29, 2005 2:10 pm
Location: Portland, Oregon

Post 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?
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post 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.
pyro9219
Posts: 14
Joined: Mon Aug 29, 2005 2:10 pm
Location: Portland, Oregon

Post 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. :/
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post 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. :/
pyro9219
Posts: 14
Joined: Mon Aug 29, 2005 2:10 pm
Location: Portland, Oregon

Post 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 :]
netpipe
Posts: 669
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: Key Binding or Forwarding help?

Post 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
Last edited by netpipe on Mon Jun 20, 2022 7:25 am, edited 1 time in total.
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Key Binding or Forwarding help?

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply