1

I am wondering if anyone might be able to give me a little help with xinput (for and Xbox controller) and vb.net.

What I am trying to do is translate the analog stick motions to certain events in my application. Specifically what I am trying to do is move a map when the joystick is moved. Is it possible to use the xinput with vb.net? I'm stuck in either vb or c# based on what the COM libraries are for the application. Any attempts to add the DLL's just throws an error at me too.

Thanks for any help,

Cheers!

Cody
  • 111
  • 1
  • 3
  • Have you tried with MonoGame ? https://monogame.codeplex.com/ – aybe Jan 25 '14 at 00:22
  • No, I haven't looked into that. The application (arcgis) is windows based so there isn't any need to port it to different OS's or Mobile devices either – Cody Jan 25 '14 at 00:25
  • Additionally, you can try to create a 'dummy' game and reference it in your application if using the DLLs directly don't work properly. – aybe Jan 25 '14 at 00:32

2 Answers2

2

You can also look into http://sharpdx.org/

It's a managed XInput library. Connecting to a controller is easy:

var controller = new SharpDX.XInput.Controller(SharpDX.XInput.UserIndex.One);
if (controller.IsConnected)
{
    var state = controller.GetState();
    var x = state.Gamepad.LeftThumbX;
    var y = state.Gamepad.LeftThumbY;
}

SharpDX is available as nuget package

pieter_dv
  • 499
  • 4
  • 13
  • SharpDX.XInput is not a managed DirectX library, it is a managed XInput library. . Never the less, useful info. As this is a high-ranking result in google, I think it worth mentioning here that the SharpDX docs seem broken. You can actually view the docs of SlimDX (SharpDX is a C# implementation of SlimDX), which are much more useful. – Clive Galway Mar 17 '17 at 22:07
1

You can achieve that with MonoGame, here's a small example of a WPF application reading the value of the left thumb stick.

enter image description here

<Window x:Class="GamePadTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBlock x:Name="TextBlock1"></TextBlock>
    </Grid>
</Window>

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace GamePadTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }

        private void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            var gamePadState = GamePad.GetState(PlayerIndex.One);
            TextBlock1.Text = gamePadState.ThumbSticks.Left.ToString();
        }
    }
}

How did I do that ?

  • Installed MonoGame : https://monogame.codeplex.com/
  • Created a new WPF project and referenced "C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows8\MonoGame.Framework.dll"

Do not forget to copy SDL.DLL to your bin\Debug, grab it here: http://www.libsdl.org/release/SDL-1.2.15-win32.zip

(done under Windows 8 x64 + Visual Studio 2012)

aybe
  • 15,516
  • 9
  • 57
  • 105