How to create a virtual gamepad?

How do I start creating a “gamepad” that appears in DirectInput applications as a regular game controller, but the state of its controls is actually determined by the software?

+7
source share
4 answers

Write a device driver to make it look like one.

In particular, Windows device drivers process the so-called interrupt requests through the interrupt request protocol, which boils down to a wrapped structure and a set of buffers inside the driver.

Now the next thing you need to know is that many drivers are actually layered or stacked or whatever name you want to use. For example, to write a disk driver, you can associate it with the driver above it (as a disk class), but use the driver below it (for example, the scsi port) to actually send commands to your devices.

How real devices work. Fake devices must meet the requirements of a top-level interface, for example. drive or controller, or mouse, or whatever. However, they can do whatever they like - to return any values ​​they like.

This opens up the possibility of controlling the driver through a user mode application and pretends to be a “device”. To send a driver message, you can DeviceIoControl to it; then to receive these messages you can:

  • Configure them in the Irp that this DeviceIoControl composes.
  • Ask the driver to read them from the memory area of ​​your process.

Drivers can also access \\Registry\\Machine and various other areas of the registry that are not specific to specific users, so you can exchange data this way.

Finally, there are no claims that you cannot filter an existing IO, and not do it all with a new device. There are many options and ways you can do this.

If you are going to do this, you will need:

  • VirtualKD or an expensive debugger cable and two computers.
  • You will probably also want to start by linking to this blog post . You will find that there are essentially different names for the driver code, so I will interpret some of them:

    • WDM = Windows driver model, mostly NT driver model mixed with (some) Windows 9x.
    • KMDF = The driver structure in kernel mode is the drivers of the above type, plus the optional WDF (Windows Driver Foundation), which is a collection of libraries on top of WDM to make it faster.
    • UMDF = User-mode driver frame - write a driver without danger of kernel mode. If you can, use this, since kernel mode drivers that go wrong will be bluescreen (in the driver, bugcheck) on your system.

Change I am not very knowledgeable about DirectInput. Perhaps there is a way to override the various API controls used by redirecting DLLs and the like, which may be simpler described.

+7
source

There is an open source project vJoy: http://sourceforge.net/projects/vjoystick/ - worth a look.

+4
source

The easiest solution would be to emulate an XInput device (Xbox 360 and One). They are supported in most modern games, and the setup is very simple. Here is a C ++ project that provides this without any installed drivers or external dependencies: https://github.com/shauleiz/vXboxInterface/

+4
source

I know this is an old question, but for those interested in this topic, it is also worth looking at this project called ViGEm .

You can emulate some well-known playgrounds, such as the Microsoft Xbox 360 controller, Sony DualShock 4 controller and Microsoft Xbox One controller. The project also offers some API for interacting with these virtual controllers.

0
source

All Articles