0
WPF 앱에서 Xbox One 컨트롤러를 읽을 수 있습니까? USB 케이블을 통해 연결합니다. 버튼에서 부울 값을 얻고 스틱 및 트리거에서 아날로그 값을 읽을 수 있어야합니다. Pollu 3pi 로봇을 제어하기 위해이 값을 사용합니다.WPF 앱에서 Xbox 컨트롤러 읽기
이를 달성 할 수있는 간단한 방법이 있습니까?
WPF 앱에서 Xbox One 컨트롤러를 읽을 수 있습니까? USB 케이블을 통해 연결합니다. 버튼에서 부울 값을 얻고 스틱 및 트리거에서 아날로그 값을 읽을 수 있어야합니다. Pollu 3pi 로봇을 제어하기 위해이 값을 사용합니다.WPF 앱에서 Xbox 컨트롤러 읽기
이를 달성 할 수있는 간단한 방법이 있습니까?
시도해 보셨습니까 :) 코드 4Fun이 (가) 귀하의 컨트롤러에 도움이 될 수 있습니다. 웹 사이트에서
https://elbruno.com/2014/06/28/coding4fun-xboxone-game-controller-c-fun-time-2/
:WPF 응용 프로그램 코드의 기본보기는 다음
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Threading;
using SharpDX.XInput;
namespace ElBruno.GameController
{
public partial class MainWindow : INotifyPropertyChanged
{
DispatcherTimer _timer = new DispatcherTimer();
private string _leftAxis;
private string _rightAxis;
private string _buttons;
private Controller _controller;
public MainWindow()
{
DataContext = this;
Loaded += MainWindow_Loaded;
Closing += MainWindow_Closing;
InitializeComponent();
_timer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(100)};
_timer.Tick += _timer_Tick;
_timer.Start();
}
void _timer_Tick(object sender, EventArgs e)
{
DisplayControllerInformation();
}
void DisplayControllerInformation()
{
var state = _controller.GetState();
LeftAxis = string.Format("X: {0} Y: {1}", state.Gamepad.LeftThumbX, state.Gamepad.LeftThumbY);
RightAxis = string.Format("X: {0} Y: {1}", state.Gamepad.RightThumbX, state.Gamepad.RightThumbX);
//Buttons = string.Format("A: {0} B: {1} X: {2} Y: {3}", state.Gamepad.Buttons.ToString(), state.Gamepad.LeftThumbY);
Buttons = string.Format("{0}", state.Gamepad.Buttons);
}
void MainWindow_Closing(object sender, CancelEventArgs e)
{
_controller = null;
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
_controller = new Controller(UserIndex.One);
if (_controller.IsConnected) return;
MessageBox.Show("Game Controller is not connected ... you know ;)");
App.Current.Shutdown();
}
#region Properties
public string LeftAxis
{
get
{
return _leftAxis;
}
set
{
if (value == _leftAxis) return;
_leftAxis = value;
OnPropertyChanged();
}
}
public string RightAxis
{
get
{
return _rightAxis;
}
set
{
if (value == _rightAxis) return;
_rightAxis = value;
OnPropertyChanged();
}
}
public string Buttons
{
get
{
return _buttons;
}
set
{
if (value == _buttons) return;
_buttons = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}
당신은 [SharpDX의 (HTTP를 사용할 수 있습니다 : // sharpdx.org/) DirectInput 또는 유사합니다. 이 기능은 모든 입력 장치의 비교적 쉬운 상호 작용을 허용합니다. – SharpShade
Xbox 컨트롤러가 DirectInput을 사용하지 않고 기본 USB 드라이버를 사용하는 경우 https://msdn.microsoft.com/en-us/library/windows/hardware/ff540174%28v=vs.85%29.aspx를 사용할 수 있습니다 Δf = 255 & MSPPError = -2147217396 – bradbury9