1

I'm trying to build up a new gamepad with arduino leonardo to send keystrokes to pc.

I can only make my gamepad to work such as keyboard.

After I build my gamepad and tried to use it in a pc game, I pressed a button and it can send to the PC keystrokes like "q","w","e","r" etc.

How can I send keystrokes like "Button 1", "Button 2", "Button 3" etc...?

bladekel
  • 37
  • 7
  • I'm not sure how you connect it to PC, but if you connected it as a hid device it would only behave like a real keyboard. If you want to simulate it like a Gamepad you need to make it as a hid gamepad instead. – Masoud Rahimi Jul 13 '19 at 14:52

1 Answers1

0

A HID device specifies how its data should be interpreted by providing a structure called the HID report descriptor. It seems your app is using a report descriptor designed to simulate a keyboard rather than a gamepad which is why you're seeing keystrokes instead of gamepad button inputs. You can find more information about the HID report descriptor in the Device Class Definition for HID v1.11.

The HID specification defines numeric values called "usages" that represent the intended purpose of a device. These usages are divided into "usage pages" that represent broad categories of usages. For instance, a keyboard will have the Keyboard usage from the Generic Desktop usage page. Individual inputs and outputs supported by the device also have usages, for instance the Tab key has its own usage on the Keyboard/Keypad usage page.

The report descriptor for a HID gamepad should have a top-level application collection with either the GenericDesktop/Joystick usage (UP: 0x01, U: 0x04) or the GenericDesktop/GamePad usage (UP: 0x01, U: 0x05).

Gamepad buttons should have usages from the Button usage page, starting with usage 1 for the primary button (UP: 0x09, U: 0x01). Gamepad axes should have usages from the axis range in the GenericDesktop page, typically the left thumbstick has the X and Y axis usages (X is UP: 0x01, U: 0x30 and Y is UP: 0x01, U: 0x31). If you have a D-pad it should have the Hat Switch axis usage (UP: 0x01, U: 0x39) and should report its value as a rotation.

See the HID Usage Tables v1.12 document for more information about HID usage values.

Here's an example report descriptor for a simple gamepad-like device with 12 buttons, 2 thumbsticks, 2 analog triggers, and a D-pad.

nondebug
  • 761
  • 3
  • 5