hi,
does anyone know how to implement the keyboard input in c# like: http://www.irrforge.org/index.php/Keyboard_Input
it would be a nice extension for the irrlicht wiki.
bool keyboard input with c#
-
- Posts: 11
- Joined: Tue Mar 07, 2006 8:02 am
- Location: Italy
Hi olli, the method is the same: derive a custom class from the interface IEventReceiver, like this:
Then create an istance of this class and pass it to the IrrlichtDevice, like this:
Code: Select all
class MyEventReceiver : IEventReceiver
{
public MyEventReceiver()
{
}
public bool OnEvent(Irrlicht.Event e)
{
bool Handled = true;
if( e.Type == EventType.KeyInput && !e.KeyPressedDown )
{
switch(e.Key)
{
case KeyCode.KEY_RETURN:
// do something
break;
case KeyCode.KEY_SPACE:
// do something else
break;
default:
Handled = false;
break;
}
}
else
Handled = false;
return Handled;
}
}
Code: Select all
IrrlichtDevice m_Device = new IrrlichtDevice(DriverType.DIRECT3D9, new Dimension2D(1280, 1024), 16, true, true, true);
MyEventReceiver Receiver = new MyEventReceiver();
m_Device.EventReceiver = Receiver;
hi theandrew80, thanks for the post but i seek for input method to perform smooth movement. i search for somthing like this in c#:
init:OnEvent():
main gameloop:
at the moment my solution is an evil hack
OnEvent():main gameloop:
init:
Code: Select all
bool keys[irr::KEY_KEY_CODES_COUNT];
for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++)
keys[x] = false;
Code: Select all
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return true;
}
Code: Select all
if(keys[irr::KEY_LEFT])
pos->X -= 1;
if(keys[irr::KEY_RIGHT])
pos->X += 1;
OnEvent():
Code: Select all
key = event.Key;
input = event.KeyPressedDown;
Code: Select all
if (input)
{
switch (key)
{
case KeyCode.KEY_ESCAPE:
...
i solved the problem:
OnEvent():Init:
gameloop:
OnEvent():
Code: Select all
public bool OnEvent(Event eve)
{
if (eve.Type == EventType.KeyInput)
{
keys[(int) eve.Key] = eve.KeyPressedDown;
return true;
}
return false;
}
Code: Select all
keys = new bool[(int) KeyCode.KEY_KEY_CODES_COUNT];
Code: Select all
if (keys[(int) KeyCode.KEY_UP])
do something...