Creating a ViGEm Feeder Application, C# Step-By-Step



  • 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

    Creating a new Console Application

    👉 Go ahead and launch Visual Studio

    2019-03-16-20-19-16.png

    👉 Navigate to File -> New -> Project

    2019-03-16-20-20-15.png

    👉 Select Console App (.NET Framework)

    2019-03-16-20-20-51.png

    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"

    2019-03-16-20-30-44.png

    👉 Select .NET Framework 4.5.2 from the dropdown

    2019-03-16-20-33-32.png

    👉 Navigate to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution...

    2019-03-16-20-22-55.png

    👉 Navigate to Browser, and then search for ViGEm

    2019-03-16-20-25-27.png

    👉 Select your application and press "Install"

    2019-03-16-20-26-40.png

    😄 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"

    2019-03-16-20-49-10.png

    As you can see, our code runs and we can see the inputs we set!


Log in to reply