Getting Started

After you have installed Rx Input Manager and referenced it within your project you can begin.
First you will want to add the following namespaces at the top of your main game.
using System.Reactive.Linq;
using RxInputManager;
using RxInputManager.Extensions;

RxInputManager Namespace is where the RxInputService lives runs either explicitly in the main update loop or implicitly by adding as a game component.
RxInputManager.Extensions contains all of the extensions methods (currently double, and helpers for Held-style operations).

Now to initialize the input manager. Create a variable some where within the main game class (or else where if you choose). This could be in the Initialize or Constructor. Remove the second line if you want to explicitly run the update yourself.

InputManager = new RxInputService(this.Services);
this.Components.Add(InputManager);


In the initialize function or it's own function start to map out your keys to their specified behavior.

Keyboard

Here's example of how to use the keyboard.

InputManager.GetKeyboard().KeyPressed(Keys.A)
                                               .DoubleTap()
                                               .Subscribe(KeyAction);

IDisposable sub =InputManager.GetKeyboard().KeyHeld(Keys.C)
                                               .Subscribe(key => Console.WriteLine("Key Held"));

KeyAction looks like any other function.
public void KeyAction(Keys key)
{
      Console.WriteLine("Key {0} was pressed!", key);
 }

The Subscribe function can take many things such as a lambda function (or method group like the first example). My recommendation is to use method groups whenever possible as they are a little faster and more direct (not by much). For those you need a function that returns void, and takes whatever T is in the IOServable<T>. In this case T is Keys.

A IDisposable is returned from the subscribe function. If you want to disable an action you may call dispose on the returned object. You will have to resubscribe in reenable it.





Last edited Aug 5, 2011 at 4:18 AM by RevisionD, version 2

Comments

No comments yet.