Using the Joysticks / Game Controllers Extension for Microsoft Small Basic

You are currently comparing revision 3 and revision 5. Go to current version

Using the Joysticks / Game Controllers Extension for Microsoft Small Basic

Development, Gaming, has code, en-US, Game, Small Basic, SmallBasic

[toc]

Introduction

The Joysticks and Game Controllers extension, written in C# using DirectX by gungan37, allows for the use of any game-controller in Small Basic. Such devices include joysticks, Xbox Controllers for Windows, racing wheels and pedals, flight sime sim yokes and rudder pedals and many more things, even a Wii Remote with the appropriate drivers!

First, download

Dependencies & Downloads

To use the Joysticks/Game Controllers extension you will need the extension files (a .dll and install .xml file) and the SlimDX framework: http://slimdx.googlecode.com/files/SlimDX%20Runtime%20.NET%202.0%20%28January%202012%29.msi. Next, which is a version of Microsoft DirectX for the .NET platform. You can find the SlimDX download here, and installthe Joysticks and Game Controllerdownload for the Joysticks/Game Controllers extension : http://www.mediafire.com/download.php?qbbt7j2m23gruznhere. To install Once you have both of these items downloaded, and you have installed the extensionSlimDX framework, just unzip you should be ready to advance.

You will also need to move the archive files for the Joystick/Game Controllers extension into the appropriate folder for Small Basic. By default, Small Basic is installed in Program Files (x86)/Microsoft/Small Basic for users on a 64-bit version of Windows, and then copy Program Files/Microsoft/Small Basic for users on a 32-bit version of Windows. You will need to move both the DLL .dll and XML files .xml file into the "lib" folder. You will most likely require administrator permission to your \do this.

Using the Extension in Small Basic\lib directoryBasic

You should now be ready to use this extension in Small Basic.

Now, open If you have Small Basic (or, if it is already open, you will need to close it then and re-open it)it. If you have it closed, simply open it. You should find two new classes:
Beginners can use the JoystickForSmallBasic classwhile more advanced users can use , which is for beginners, and the MUCH faster JoystickForSmallBasicAdvanced, which is for more advanced usersThe only difference is that everything is take taken care of for you in the former less advanced class , class while, in the letterlatter class, you must call the Acquire() method before polling for input and Unacquire() when you are done. For the purposes of this tutorial, we We will use be using the advanced class in this tutorial.

Take a look around the class and explore the members with the Intellisense wheel! You will notice the GetSlider(slidernumber) to get the slider value (percent) at the specified slider. You can also use GetButton(buttonnumber) to get "True" or "False" for if a button is pressed (and ButtonCount to get the total number of buttons). Finally, you can use GetPOV(pov hat index) to get the angle (in degrees) of a POV hat and GetX(), GetY(), and GetZ() to get the X, Y, and Z axis values, respectively.

Here is some good sample code(, which you can get with the Import ID FGM626)FGM626:

 

01.

start:
02.
03.
 
JoystickForSmallBasicAdvanced.Acquire()
04.
TextWindow.Title = "Joystick Information"
05.
TextWindow.WriteLine("")
06.
TextWindow.WriteLine("Axis position: " + JoystickForSmallBasicAdvanced.GetX() + ", " + JoystickForSmallBasicAdvanced.GetY() + ", " + JoystickForSmallBasicAdvanced.GetZ())
07.
08.
 
slider = JoystickForSmallBasicAdvanced.GetSlider(0) 'get slider #0 value
09.
slider = (slider / 65536) * 100 'convert to a percent
10.percentage
slider = 100 - slider 'flip value (DirectX gives value backwards)
11.
12.
 
TextWindow.WriteLine("Slider position: " + Math.Round(slider) + "%")
13.
TextWindow.WriteLine("POV hat position: " + JoystickForSmallBasicAdvanced.GetPOV(0) + "°")
14.
TextWindow.WriteLine("Firmware revision: " + JoystickForSmallBasicAdvanced.FirmwareRevision)
15.
TextWindow.WriteLine("")
16.
TextWindow.Write("Buttons: ")
17.
For i = 0 To (JoystickForSmallBasicAdvanced.ButtonCount - 1) 'since buttons start with zero
18.
  If JoystickForSmallBasicAdvanced.GetButton(i) = "True" Then
19.
    TextWindow.Write(" " + i + " ")
20.
  EndIf
21.
EndFor
22.
23.
 
Program.Delay(120) 'delay so user can read info
24.
TextWindow.Clear()
25.
26.
 
Goto start

Happy coding!