I want to be able to support all input devices. Ones that exist, ones that don't exist yet. Ones that you make yourself.
So I have come up with a system to do that.
It relies on using HID and USB. These types of devices just supply you a bit stream and you have to work out what it means. So that is the first stage.
Creating bitstream mapping tablesI will write a tool to make this easy one day, but for the moment I just use a hacked together tool modified from an excellent HID library on the web.
I select the device I am interested in and you get a real time display of the bytes.
Then I start wiggling the controls and pressing buttons to see what changes.
It's fiddly, but it works. You end up with a mapping table like this....
10:Left:Throttle
10:Right:Throttle
1:EButton:Button
1:RTY1CLICK:Button
1:RTY2CLICK:Button
1:IBUTTON:Button
.......
So 10 bits for the left throttle ... 10 bits for the right throttle .. etc.
Once you have this you can use that to create an input device in the game. It has support for buttons, throttles, sliders, thumbsticks, hi-hats, and clickers (like a mouse wheel).
The next stage is to create an image to use in the configuration screen
This has to be saved as <Game path>\Devices\<Device Name>\backdrop.png
The size doesn't matter, the code has scrolling support. The important thing is to have a window for every input.
Then you need to create a text file. This links the image to the code.
This has to be saved as <Game path>\Devices\<Device Name>\Layout.txt
Inside it you have three regions
- Scroll Positions deltas to add to the bitmaps display position if a particular button is pressed
- HiLIghtRegions the position and size of the windows for each input
- ScreenPosition the position to display the image on the screen
So you end up with something like this.
ScrollPositions 0
HiLightRegions 39
SW1 84 644 116 18
SW2 84 663 116 19
SW3 236 644 115 19
SW4 236 663 115 19
SW5 388 644 115 19
SW6 388 663 115 19
TGL4UP 533 135 115 16
TGL4DOWN 533 154 115 18
TGL3UP 533 230 115 16
TGL3DOWN 533 248 115 18
TGL2UP 533 324 115 16
TGL2DOWN 533 342 115 18
TGL1UP 537 419 115 16
TGL1DOWN 537 437 115 18
RTY1 934 229 115 17
RTY2 938 349 115 17
RTY3 537 512 115 18
RTY4 538 607 115 18
RTY1C 934 249 115 17
RTY2C 939 369 115 17
H3UP 939 443 115 17
H3DOWN 939 461 115 17
H3LEFT 939 481 115 17
H3RIGHT 939 499 115 17
H4UP 941 600 115 17
H4DOWN 941 619 115 17
H4LEFT 941 638 115 17
H4RIGHT 941 657 115 17
SLD 703 210 115 17
EBUTTON 703 229 115 18
THUMBSTICK 840 49 115 18
K1UP 136 40 115 18
K1DOWN 136 59 115 18
IBUTTON 325 43 115 18
HBUTTON 488 42 115 18
CLICKWHEELUP 4 286 65 17
CLICKWHEELDOWN 4 305 65 17
Left 155 352 85 17
Right 274 352 85 17
ScreenPosition 20 20
Now you can load it in the game.
The in game procedure is simple. Move a control or press a button and it is lit up to show you it has been detected. Then select an aircraft specific event you want to map it to.
The event list will be extracted from the aircraft's gameobject. Well it will be eventually, at the moment I am still building up all the key events and supporting components, but that's another story.
The list on the right is a folding scrollable list to make it easier to navigate.
I will try and put up a video if google ever let me use my account