This project is read-only.
InputHandlers V1.1 Quick Start Guide

Loading the project in your existing project

To incorporate this project into your existing project, do the following: right click your Solution, Add... then Existing Project, then choose the inputhandlers.csproj file. Then go to your existing project's references list, right click, Add Reference, Projects tab, inputhandlers, OK.

Using InputHandlers

Step 1 - Using statements

using InputHandlers.Mouse;
using InputHandlers.Keyboard;

Step 2 - initialisation

The two handlers are implemented as singletons because there should only ever be one keyboard and one mouse handler for the whole application.

Create memory for the singletons. You have a number of options:
- call reset:

- copy the singleton reference to your own local variables:
MouseHandler mouse = MouseHandler.Instance;
KBHandler kb = KBHandler.Instance;

- do neither of the above; the handler will be instantiated the first time you dereference the singleton via .Instance

Step 3 - create a class that you want to have event handlers. It will implement the two interfaces

public class handlersclass : IMouseHandlers, IKBHandlers

Step 4 - Now you must implement the interface. Inside this class, write your implementation for each interface method inside the curly brackets (the ones you dont want still need to be here as per interface rules, but leave them blank):

public void HandleMouseScrollWheelMove(MouseState m, int diff) { }
public void HandleMouseMoving(MouseState m) { }
public void HandleLeftMouseClick(MouseState m) { }
public void HandleLeftMouseDoubleClick(MouseState m) { }
public void HandleLeftMouseDown(MouseState m) { }
public void HandleLeftMouseUp(MouseState m) { }
public void HandleLeftMouseDragging(MouseState m, MouseState origin) { }
public void HandleLeftMouseDragDone(MouseState m, MouseState origin) { }
public void HandleRightMouseClick(MouseState m) { }
public void HandleRightMouseDoubleClick(MouseState m) { }
public void HandleRightMouseDown(MouseState m) { }
public void HandleRightMouseUp(MouseState m) { }
public void HandleRightMouseDragging(MouseState m, MouseState origin) { }
public void HandleRightMouseDragDone(MouseState m, MouseState origin) { }

public void HandleKBKeyDown(Keys[] klist, Keys focus, KBModifiers m) { }
public void HandleKBKeyLost(Keys[] klist, KBModifiers m) { }
public void HandleKBKeyRepeat(Keys repeatkey, KBModifiers m) { }
public void HandleKBKeysReleased() { }

Now here's the part that may be difficult to comprehend. There are two additional methods you must implement also:
void AddMouseEvents() {}
void AddKBEvents() {}

Inside these you must add a delegate of your above interface methods to the handler's event object. For example, to add your HandleMouseScrollWheelMove method, do the following:

mouse.HandleMouseScrollWheelMove += new MouseHandler.DelHandleMouseScrollWheelMove(this.HandleMouseScrollWheelMove);

Note - you only have to add the events that you provided an implementation for.

Step 5 - call your AddMouseEvents and AddKBEvents somewhere in your initialisation code


Step 6 - In the XNA Framework's Update() function, Poll the handlers. This will cause the handler's event object to fire if an action was found, which will in turn call all the delegates that have been added (i.e. the interface method you implemented in your class)


Using the sample project

Ensure you have downloaded both the InputHandlers and InputHandlersSample and extract them to the same parent directory. Open up the inputhandlerssample.sln file. This should automatically open up the inputhandlers solution. If it doesnt, you'll have to manually add it using the “Loading the project in your existing project” instructions provided above.

Further Documentation

Use the Class View in Visual Studio to see the various methods and properties available to your application. The source code is well commented.

Last edited Sep 30, 2012 at 4:08 AM by DireAussie, version 3


No comments yet.