如何在自定义编写的 C 游戏或程序中使用 USB 控制器
问题 厌倦了编写对角移动精灵和角色的函数并分配不与 4 个主要方向键(上、下、左、右)(例如 W、A、S、D)配合的键,这有点拖沓,一个无聊。不过我最近得到了这个 USB 控制器 http://www.logitech.com/ en-us/gaming/controllers/devices/288 我希望能够将其用法添加到我基于控制台的游戏或 Windows 应用程序中。因为它有模拟摇杆,支持舒适的对角线移动。
解决方法/可能的解决方案 有大量关于在 C# 中执行此操作的文档,但我更喜欢 C,并且对 C# 几乎一无所知。
问题 是否可以在没有额外库的情况下使用 C 语言,如果可以,我如何在我的程序中使用 USB 控制器支持(并将该功能添加到我未来的项目中)。非常感谢任何资源或提示。欢迎使用 Linux 或 Windows 解决方案。提前致谢。
Problem
Having grown tired of writing functions to move sprites and characters diagonally and assigning keys that do not flow with the 4 main directional keys(UP, DOWN, LEFT, RIGHT) such as W,A,S,D is a bit of a drag and a bore. However i recently got this usb controller http://www.logitech.com/en-us/gaming/controllers/devices/288 and i would like to be able to add its usage to my console based games or windows applications. AS it has the analog sticks that support comfortable diagonal movement.
Workaround/Possible Solution
There is a fair amount of documentation on doing this in C# but i am more comfortable in C and know next to nothing about C#.
Question
Is it possible in C without additional libraries and if so how can i could use the usb controller support in my programs(and add the functionality to my future projects). Any resources or tips are much appreciated. Linux or Windows solutions are welcome. thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 Windows,您可以尝试直接输入,或XInput对操纵杆和游戏手柄有出色的支持。它也用于 Xbox 开发。许多游戏项目都使用它,这里有一个完整的列表
另一个不错的选择是SDL,它对 GamePad 有足够的支持(在 Windows 系统上构建于 DirectInput 之上),并且平台无关,因此这可能是一个优势。另外,我认为 Allegro 支持它们,但我不确定。
注意:抱歉,如果您不打算重新发明轮子并为市场上每个该死的 GamePad 编写驱动程序和 API,那么您将不得不使用额外的库。
If you are using Windows you may try Direct Input, or XInput it has excellent support for Joysticks and GamePads. It is also used in XBox development. Many Game Projects use this, here is a complete list
Another good option is SDL, it has adequate support for GamePads (which is built on top of DirectInput on Windows Systems) and is Platform-Independent , so that may be an advantage. Also I think Allegro supports them, but I'm not sure.
NOTE: Sorry, if you don't intend to reinvent the wheel and write a driver and api for every damn GamePad in the market, you'll have to use an additional library.