the Fiddler's picture

[Input] Add static classes for Mouse, Keyboard and GamePad input

Project:The Open Toolkit library

These classes should be independent of the GameWindow and usable on their own. Proposed API:

MouseState OpenTK.Input.Mouse.GetState(int index);
KeyboardState OpenTK.Input.Keyboard.GetState(int index);
GamePadState OpenTK.Input.GamePad.GetState(int index);

[Mouse|Keyboard|GamePad]State are structs that encapsulate the state vector of the relevant device at the time when GetState was called. 'Index' is an optional parameter that specifies which device is queried, when multiple devices are connected to the computer. It is not an error to query a device index for a non-existent device: in that case, the state vector will indicate IsConnected = false.

Device indices may not after application startup. For example, if the computer has 3 devices (0, 1, 2) and device 1 is disconnected, the indices of the other devices may not change: they shall remain (0, 2).


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Mincus's picture


I'm running revision 2701 and still getting the same bug under Windows 7 (x64)

I had a look through the code, from what I can tell the joystick driver isn't being polled anywhere.
Adding InputDriver.Poll() to GameWindow.RaiseUpdateFrame() just before the call to OnUpdateFrameInternal() works, but I'm unsure whether this is where it should be and obviously InputDriver is marked as deprecated.

This isn't urgent btw. As I say I've now got an implementation with the basic behaviour (if not necessarily optimised) which will do me until the new API is implemented.

jdomnitz's picture


Any chance this can be revisited now that 1.0 is released?

the Fiddler's picture


Version:0.9.x-dev» 1.1-dev
Status:postponed» confirmed

Yes, that would be a very good idea.

the Fiddler's picture


Status:confirmed» in progress

An initial implementation for X11 is now committed to trunk. Windows and Mac OS X implementations are on the way.

jdomnitz's picture


wow you work fast :) is the multi-device support planned as well?

the Fiddler's picture


I have been working on this on and off a couple of years. :)

Multi-device support? You can bet on it.

the Fiddler's picture


I've just committed an XInput1 and XInput2 mouse drivers for Linux. The former is supported everywhere but can only provide absolute mouse movements, which means it is constrained to the window or monitor. The latter requires a very recent xserver but provides relative motion, raw input (without pointer ballistics), multi-mouse (to be done) and several other nice perks.

jdomnitz's picture


Great work (as usual)!!

One thing I would like to see done differently is the CreateMouseDriver() function in X11Factory. Throwing and catching exceptions is very slow in .net and should be avoided as much as possible. It seems like checking the extension in that function would make a lot more sense and avoid an unnecessary exception.

I imagine XListInputDevices is coming soon and the ability to pick specific devices. What about events? How will these be handled in a multimouse setup or would this be a polling only system?

the Fiddler's picture


XInput2 support is now detected without throwing an exception. Device detection will be coming later on (XI2-only, since XI1 is fundamentally broken) and I hope to add tablet and pen support at some future point. I'm still performing basic sanity checks right now (input grabbing, multi-threading).

These APIs are polling-only. They are meant to be thread-safe and events won't work as expected. However, GameWindow will still provide event-based input for GUIs, similar to GLControl/WinForms.

jdomnitz's picture


Fix looks good thanks...

Will the GameWindow's event based input be built on top of these APIs or will there be two different API layers to do the same thing?