![jumpstorydownload20200403001517 | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/jumpstory-download20200403-001517.jpg?resize=1140%2C694&ssl=1)
Winsoft’s Controller is a XInput API controller SDK. XInput a universal joystick controller for Windows 7, 8, 10.
In the Windows platform, you can use other joysticks, such as PlayStation Dual-Shock Controller, Nintendo Switch Pro Controller and Steam Controller if you don’t have a XBOX joystick controller.
Table of Contents
Winsoft Controller Installation
Steps:
- Go to https://www.winsoft.sk/controller.htm for the download link.
- Download the trial version.
- Install Controller.exe
- Find Winsoft’s Controller installed in C:\Program Files (x86)\Winsoft\Controller\ and example in C:\Program Files (x86)\Winsoft\Controller\Examples\Delphi\Demo.dproj.
- If you want to add Winsoft’s DirectX path controller, go to Language > Delphi > Library >
![202009291354241 | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/09/2020-09-29_13-54-24-1.png?resize=750%2C557&ssl=1)
Setting up the XBOX Controller
Prior to starting, go to Control Panel > Devices and Printers.
- Right-click on the joystick icon.
- Go to Game controller settings.
- Ensure status is OK.
If the status is not OK, please install the XBOX redistributable framework 4.0 and DirectX 9.0 run-time.
![2020082622723 | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/09/2020-08-26_2-27-23.png?resize=750%2C349&ssl=1)
Quick Joystick Support
I have made changes to the Delphi Stater Kit game Alien Invasion.
I first drag and drop the TController from the (1) component palette to form (2).
![alieninvasion2 | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/09/alieninvasion2.png?resize=750%2C318&ssl=1)
I then add code to get button press data from Controller.Buttons and respond to btUp as a Key-Up event.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Buttons := GamepadFrame.Controller.Buttons; if (btLeft in Buttons) then begin Key := vkLeft; end else if (btRight in Buttons) then begin Key := vkRight; end else if (btUp in Buttons) or (btA in Buttons) or (btB in Buttons) or (btX in Buttons) or (btY in Buttons) then begin Key := vkUp; end else if (btStart in Buttons) then begin isPaused := not isPaused; Exit; end; |
Loading and Saving Controller Settings
![2020082620425 | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/09/2020-08-26_2-04-25.png?resize=614%2C395&ssl=1)
In order to load Joystick controller settings, I load ControllerIndex. If the setting is more than 1 (i.e, 0 = (none), 1 = Device 0), I enable the Joystick Controller, or else, Joystick is disabled.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// type TGameForm = class(TForm) //... ControllerIndex : Integer; end; procedure TGameForm.LoadSettings; var IniFile: TMemIniFile; begin IniFile := TMemIniFile.Create(SettingsFilePath + 'Settings.ini'); //... ControllerIndex := IniFile.ReadInteger('Settings', 'Controller', 0); if (ControllerIndex > 0) then begin GamepadFrame.Controller.Device := ControllerIndex - 1; GamepadFrame.Controller.Enabled; GamepadFrame.Timer.Enabled := true; end else begin GamepadFrame.Controller.Disable; GamepadFrame.Timer.Enabled := false; end; //... end; |
In order to save controller setting, I save the ControllerIndex.
1 2 3 4 5 6 7 8 9 10 |
procedure TGameForm.SaveSettings; var IniFile: TMemIniFile; begin IniFile := TMemIniFile.Create(SettingsFilePath + 'Settings.ini'); //... IniFile.WriteInteger('Settings', 'Controller', ControllerIndex); IniFile.UpdateFile; IniFile.Free; end; |
The GIT repository for the Alien Invasion modifications to work with Winsoft Controller is at https://github.com/PolywickStudio/DelphiAlienInvasion
Winsoft sells the full-version at their website.
- Works with: Delphi, C++Builder, FMX, VCL
- Works on: Windows 32-bit, Windows 64-bit
Conclusion: In less than 30 lines of code, I have demonstrated adding Joystick support to your game. WINSOFT saves game-development time.
Check out the full WINSOFT Controller for Delphi and C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition