Making a controller emulator...

BlitzMax Forums/BlitzMax Beginners Area/Making a controller emulator...

Ryan Burnside(Posted 2010) [#1]
I'm wanting to make a controller emulator for my PC. I know some ultilities like joy2key have the ability to run in the background and map joystick presses to keyboard keys. This is especially useful for making any PC game compatable with the joystick.

It works like this
1 joystick button press detected
2 program emulates the keystroke
3 game detects and accepts the forced keystroke

I know there is code to emulate keystrokes with Blitzmax but my problem is how to get the program to run in an unwindowed mode and still accept joystick key presses and output keystrokes. I just think it would be cool to code my own utility for this rather than using a premade one.

I'm using this for a Windows machine.


Gabriel(Posted 2010) [#2]
You'd probably need to use this:

http://msdn.microsoft.com/en-us/library/ms681956(VS.85).aspx


Ryan Burnside(Posted 2010) [#3]
Thank you Gabriel. I'm not how to incorporate this into my project. Can you offer any further help please? I assume I need to package the .dll with my code but how do I use the functions from the .dll in my own project?


plash(Posted 2010) [#4]
User32.dll is a standard library on all Windows versions.

To use functions and such from system libraries, you simply need to define them in an extern block.
For example, AttachThreadInput would look something like this (may be incorrect, as I am not on Windows to test it):
Extern "Win32"
	Function AttachThreadInput:Int(idAttach:Short, idAttachTo:Short, fAttach:Int) = "AttachThreadInput@12"
End Extern


Though, I don't know exactly what Gabriel is suggesting you do with that..


Gabriel(Posted 2010) [#5]
Well, to the best of my knowledge, you can't normally get input from another process. Typically, to get input from another process you have to use AttachThreadInput. Maybe there are other ways, much simpler ways, but it's the only one I know of, so I suggested it.

I don't know anything about Joy2Key but I did a quick google when I read the question and the info I found seemed to suggest that Joy2Key uses something like this to inject the keyboard input into processes too.