Please, help me. I looked through entire forum and I still have a problem with keyboard. Now my code complains: "Object reference not set to an instance of an object".
using System;
using Irrlicht;
using Irrlicht.Video;
using Irrlicht.Core;
using Irrlicht.Scene;
namespace HelloWorld
{
// static IrrlichtDevice device = null;
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:
break;
case KeyCode.KEY_SPACE:
// do something else
break;
default:
Handled = false;
break;
}
}
else
Handled = false;
return Handled;
}
}
class rrr
{
[STAThread]
static void Main()
{
IrrlichtDevice device = new IrrlichtDevice(DriverType.DIRECT3D9, new Dimension2D(800, 600), 16, false, true, true);
MyEventReceiver Receiver = new MyEventReceiver();
device.EventReceiver = Receiver;
ITexture tex =device.VideoDriver.GetTexture(@"1.jpg");
Irrlicht.Scene.IAnimatedMesh mesh = device.SceneManager.GetMesh(@"1.x");
ICameraSceneNode cam = device.SceneManager.AddCameraSceneNodeFPS(null, 100, 100, -1);
cam.Position = new Vector3D(20,0,-50);
ISceneNode node = device.SceneManager.AddAnimatedMeshSceneNode(mesh, null, -1);
node.SetMaterialTexture(0, tex);
node.SetMaterialFlag(MaterialFlag.LIGHTING, false);
device.CursorControl.Visible = false;
while(device.Run())
{
if (device.WindowActive)
{
device.VideoDriver.BeginScene(true, true, new Color(0,100,100,100));
device.SceneManager.DrawAll();
device.VideoDriver.EndScene();
device.WindowCaption=EventType.LogText.ToString();
}
} // end drawing-loop
} // end main()
} // end class
} // end namespace
C# - Detect Keyboard Input
-
- Posts: 11
- Joined: Mon Jan 22, 2007 5:42 pm
- Location: Tbilisi, Georgia, Eastern Europe
- Contact:
using a form in vb2005
I got it to work in vb2005 using a form's class by
and building the proxy function:
as part of the form's class....then all I needed to do was set the device.eventreceiver to point to the form..... But then again I am barely competent at reading c# code, but it apears that you also declared a new ieventreceiver, which I did not.
anyway...Hope this is SOME help at least, because it was VERY frustrating to me too.
Kiwsa
Code: Select all
implements Ieventreceiver
and building the proxy function:
Code: Select all
Public Function OnEvent(ByVal e As Irrlicht.Event) As Boolean Implements Irrlicht.IEventReceiver.OnEvent
If e.Type = EventType.KeyInput And e.Key = KeyCode.KEY_ESCAPE Then
shutdown = True
End If
End Function
anyway...Hope this is SOME help at least, because it was VERY frustrating to me too.
Kiwsa
-
- Posts: 11
- Joined: Mon Jan 22, 2007 5:42 pm
- Location: Tbilisi, Georgia, Eastern Europe
- Contact:
Kiwsa, Thank you, but I still have problem. I removed all unnecessary code and this code works, I mean sintax is correct, but keyboard still doesn't work
using System;
using Irrlicht;
using Irrlicht.Video;
using Irrlicht.Core;
using Irrlicht.Scene;
namespace HelloWorld
{
class Example : IEventReceiver
{
public bool OnEvent(Irrlicht.Event e )
{
if (e.Type == EventType.KeyInput)
{
Environment.Exit(0) ;
return true;
}
return false;
}
static void Main(string[] args)
{
IrrlichtDevice device = new IrrlichtDevice(DriverType.OPENGL,new Dimension2D(800, 600),32,false,true,true);
ITexture texSydney = device.VideoDriver.GetTexture(@"1.jpg");
Irrlicht.Scene.IAnimatedMesh mesh = device.SceneManager.GetMesh(@"1.x");
ICameraSceneNode cam = device.SceneManager.AddCameraSceneNodeFPS(null, 100, 100, -1);
cam.Position = new Vector3D(20,0,-150);
ISceneNode node = device.SceneManager.AddAnimatedMeshSceneNode(mesh, null, -1);
node.SetMaterialTexture(0, texSydney);
node.SetMaterialFlag(MaterialFlag.LIGHTING, false);
while(device.Run())
{
if (device.WindowActive)
{
device.VideoDriver.BeginScene(true, true, new Color(0,100,100,100));
device.SceneManager.DrawAll();
device.VideoDriver.EndScene();
}
} // end drawing-loop
} // end main()
} // end class
} // end namespace
using System;
using Irrlicht;
using Irrlicht.Video;
using Irrlicht.Core;
using Irrlicht.Scene;
namespace HelloWorld
{
class Example : IEventReceiver
{
public bool OnEvent(Irrlicht.Event e )
{
if (e.Type == EventType.KeyInput)
{
Environment.Exit(0) ;
return true;
}
return false;
}
static void Main(string[] args)
{
IrrlichtDevice device = new IrrlichtDevice(DriverType.OPENGL,new Dimension2D(800, 600),32,false,true,true);
ITexture texSydney = device.VideoDriver.GetTexture(@"1.jpg");
Irrlicht.Scene.IAnimatedMesh mesh = device.SceneManager.GetMesh(@"1.x");
ICameraSceneNode cam = device.SceneManager.AddCameraSceneNodeFPS(null, 100, 100, -1);
cam.Position = new Vector3D(20,0,-150);
ISceneNode node = device.SceneManager.AddAnimatedMeshSceneNode(mesh, null, -1);
node.SetMaterialTexture(0, texSydney);
node.SetMaterialFlag(MaterialFlag.LIGHTING, false);
while(device.Run())
{
if (device.WindowActive)
{
device.VideoDriver.BeginScene(true, true, new Color(0,100,100,100));
device.SceneManager.DrawAll();
device.VideoDriver.EndScene();
}
} // end drawing-loop
} // end main()
} // end class
} // end namespace
-
- Posts: 11
- Joined: Mon Jan 22, 2007 5:42 pm
- Location: Tbilisi, Georgia, Eastern Europe
- Contact:
I tried everything, but I still can't make it work
Please, can anybody rewrite this code to me ??? I will appreciate deeply.
Please, can anybody rewrite this code to me ??? I will appreciate deeply.
Code: Select all
using System;
using Irrlicht;
using Irrlicht.Video;
using Irrlicht.Core;
using Irrlicht.Scene;
namespace HelloWorld
{
public class MyEventReceiver : IEventReceiver
{
//public MyEventReceiver() //constructor
//{
//}
public bool OnEvent(Irrlicht.Event e )
{
if (e.Type == EventType.KeyInput)
{
Environment.Exit(0) ;
return true;
}
return false;
}
public void run()
{
IrrlichtDevice device = new IrrlichtDevice(DriverType.DIRECT3D9, new Dimension2D(800, 600), 16, false, true, true);
device.EventReceiver =this;
ITexture tex =device.VideoDriver.GetTexture(@"1.jpg");
Irrlicht.Scene.IAnimatedMesh mesh = device.SceneManager.GetMesh(@"1.x");
ICameraSceneNode cam = device.SceneManager.AddCameraSceneNodeFPS(null, 100, 100, -1);
cam.Position = new Vector3D(20,0,-50);
ISceneNode node = device.SceneManager.AddAnimatedMeshSceneNode(mesh, null, -1);
node.SetMaterialTexture(0, tex);
node.SetMaterialFlag(MaterialFlag.LIGHTING, false);
device.CursorControl.Visible = false;
while(device.Run())
{
if (device.WindowActive)
{
device.VideoDriver.BeginScene(true, true, new Color(0,100,100,100));
device.SceneManager.DrawAll();
device.VideoDriver.EndScene();
device.WindowCaption=EventType.LogText.ToString();
}
} // end drawing-loop
} // end run
} // end class
public class mainclass
{
[STAThread]
static void Main()
{
MyEventReceiver zzz=new MyEventReceiver();
zzz.run();
}
}
} // end namespace
-
- Posts: 11
- Joined: Mon Jan 22, 2007 5:42 pm
- Location: Tbilisi, Georgia, Eastern Europe
- Contact:
-
- Posts: 11
- Joined: Mon Jan 22, 2007 5:42 pm
- Location: Tbilisi, Georgia, Eastern Europe
- Contact: