wpf - 添加使用 DirectInput 设备时 WPF 应用程序挂起
问题描述
我曾经使用 Microsoft.DirectX.DirectInput.Device 类将操纵杆添加到我的 WinForms 应用程序中。现在我想用 WPF 做同样的事情。
这是我正在使用的一个非常简单的代码示例。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Interop;
using Microsoft.DirectX.DirectInput;
namespace JoysticksTest
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// HANGS WHEN ENTERING DetectInstalledDevices METHOD!!!
DetectInstalledDevices();
}
private void DetectInstalledDevices()
{
// Find all the GameControl devices that are attached.
DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);
// check that we have at least one device.
if (gameControllerList.Count > 0)
{
for (int i = 0; i < gameControllerList.Count; i++)
{
// Move to the first device
gameControllerList.MoveNext();
DeviceInstance deviceInstance = (DeviceInstance)gameControllerList.Current;
if (deviceInstance.DeviceType == DeviceType.Joystick)
{
// Some code here
}
}
}
}
}
}
但我的 WPF 应用程序只是挂起。
我究竟做错了什么?我的电脑上安装了 Windows 8.1 操作系统。
是 WPF 还是 Microsoft.DirectX.DirectInput.dll 的错误版本?
解决方案
推荐阅读
- fortran - 使 SUM 函数与派生类型一起使用
- sql - string_agg(character_variing) 不存在
- xcode - 在 XCUITest 中检查应用程序安装
- python - 这是一个无约束的多变量优化问题,是解决的最佳方法吗?
- ubuntu - 如何在 Windows 上运行多个 WSL2 实例?
- php - 如何在 laravel Blade 中渲染 html
- rust - 确保 actix 按时间顺序记录 // 预处理
- javascript - 组件内部的 Apollo 状态管理
- machine-learning - Band RNN 的计算精度
- r - 闪亮的每日数据刷新