Controller Driver

Tsaar

Guest
Apr 15, 2010
228
0
76
I am an Electrical Engineer with some rudimentary programming knowledge in C/C++ (mostly DSP or embedded systems work).

I am wanting to become a better programmer by doing some little useful apps on my PC.

I bought an Xbox 360 controller for my computer and there are quite a few games without native support. There are 3rd party apps that solve this problem. First, I am paranoid and don't like to install software unless its from a trusted developer/publisher. Second, and less important, most cost money.

The driver is already installed from MS. What I need is to interpret the controller inputs and assign it to a standard keyboard input.

Does anyone have any advice? I don't even know where to start with this.
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
http://en.wikipedia.org/wiki/DirectInput

http://msdn.microsoft.com/library/default.aspx

These are the two links you'll need to be familiar with.

XInput is the directX method of working with input devices (and, afaik, the only method for working with the xbox 360 controller). You might have to download the directX sdk to get started (you really need to us visual studios to use the directX sdk).

The next link is to the msdn. It is microsoft's programming documentation for pretty much everything microsoft related. In there, you'll want to read up on the Win32 API. Be forewarned, emulating key presses is very tedious, more so than you might think. In fact, for a given game, it may not be possible depending on how they handle a key press. (They might look at the state of the keyboard, in which case, you are pretty much screwed.)

Something you might find useful. All windows applications operate around a message pumping loop. Windows will read the state of the system, and store messages for each application on the system. This message pumping loop will grab that message and then dispatch it to a message handling function which will handle the interpretation of those messages. The standard windows application receives keystroke information through this pumping process. Windows will store a "KEY_UP" message with the data set to identify which key it was. It is up to the application to act according the key that was received.

From an external application, you can push whatever message you like into another applications message queue. To do this, you first need to get the handle to that window (commonly abbreviated as HWND), after that, it is a simple "PostMessage" and you are off (There is also a SendMessage function, IIRC it is blocking and waits for the message to leave the queue).

Again, what will work will depend a lot on how the application is setup to read the keyboard. It is possible to just look directly at they keyboard state and act according to that.
 

Tsaar

Guest
Apr 15, 2010
228
0
76
Thanks for the great reply. I am now thinking I may not have time for such a project haha.

I have student access to MSDN for free Visual Studio and such.

Basically how I envisioned doing it was using a simple GUI created in visual studio with each button represented (I would probably hardwire the joysticks to be WASD and arrows), and then you can choose which keyboard letter each button represented. I did not even consider the fact that some games may directly monitor the keyboard though.

I just think with full time engineering work and grad school at night this may be a little too much for now.

I will think on it though. I have been reading through the Xinput API on MSDN.