Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Prints a message when keys are pressed.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
public class KeyboardExample : Game
{
private GraphicsDeviceManager _graphics;
public KeyboardExample() { _graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; }
protected override void Update(GameTime gameTime)
{
var kstate = Keyboard.GetState();
if (kstate.IsKeyDown(Keys.Space)) { System.Console.WriteLine("Space pressed"); }
base.Update(gameTime);
}
}MonoGame is an open-source, cross-platform game development framework written in C# and based on Microsoft’s XNA framework. It enables developers to build 2D and 3D games for multiple platforms using a single codebase.
Origin & Creator
MonoGame was created as an open-source implementation of Microsoft XNA in 2009 by Xamarin contributors, continuing XNA’s legacy for cross-platform development.
Industrial Note
MonoGame is popular for developers who want XNA-style development in C# with multi-platform deployment, including Windows, Mac, Linux, iOS, Android, consoles, and web via WebAssembly.