ViGEm.NET Feeder Example
This guide assumes you have a basic knowledge of C# and Visual Studio. It currently uses the new .NET refine API
Prerequisites
- Visual Studio 2017
- .NET Framework 4.5.2 or higher
Creating a new Console Application
Go ahead and launch Visual Studio
Navigate to File -> New -> Project
Select Console App (.NET Framework)
Installing the NuGet
I do indeed love some nougat bars... oh... wrong kind of nuget
Before you can do anything, you MUST target .NET Framework 4.5.2 or greater!
Right click your project and select "Properties"
Select .NET Framework 4.5.2 from the dropdown
Navigate to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution...
Navigate to Browser, and then search for ViGEm
Select your application and press "Install"
Congratulations! Go buy yourself a... breadstick
Writing the code
Boom! The Code!
using System.Threading;
using Nefarius.ViGEm.Client;
using Nefarius.ViGEm.Client.Targets;
using Nefarius.ViGEm.Client.Targets.Xbox360;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
ViGEmClient client = new ViGEmClient();
IXbox360Controller controller = client.CreateXbox360Controller();
controller.Connect();
//minimum of -32768, maximum of 32767
controller.SetAxisValue(Xbox360Axis.LeftThumbX, -32768);
//true or false
controller.SetButtonState(Xbox360Button.X, true);
//minimum of 0, maximum of 255
controller.SetSliderValue(Xbox360Slider.LeftTrigger, 255);
Thread.Sleep(5000);
}
}
}
An explanation of what this does you may ask
Well... I have an answer!
ViGEmClient client = new ViGEmClient();
This spawns our ViGEmClient object
IXbox360Controller controller = client.CreateXbox360Controller();
This gives us our XBox360 controller which is derived from the VirtualGamepad interface
//minimum of -32768, maximum of 32767
controller.SetAxisValue(Xbox360Axis.LeftThumbX, -32768);
This sets the Left Thumb X axis to 100% to the left. -32768 is the maximum "left" value and 32767 is the maximum "right" value
//true or false
controller.SetButtonState(Xbox360Button.X, true);
This sets the virtual Xbox360 X button to active. It can only be enabled (true) or disabled (false)
//minimum of 0, maximum of 255
controller.SetSliderValue(Xbox360Slider.LeftTrigger, 255);
This sets the virtual Xbox360 LeftTrigger to be fully pressed
Checking our code
The built in windows utility joy.cpl is quite bad as it only polls devices when the window is focused. In our case, we'll be using the program called "XInput Controller Tester"
As you can see, our code runs and we can see the inputs we set!