The NEW Build Your Own Arcade Controls
Main => Software Forum => Topic started by: ahofle on August 14, 2007, 03:39:33 pm
-
I am trying to get some keystrokes sent to MAME via an external application. I have tried SendKeys, SendInput, and even keybd_event. They all work fine in windows apps like Notepad, but MAME doesn't respond at all. I know keybd_event works for the special LED keys like numlock (ledutil uses it), but I can't get other keys sent. Any hints would be appreciated.
-
You can use a DirectInput hook.
-
Thanks, can you elaborate on that a bit? I have the key hooking part already working, I am just trying to send keystrokes.
-
You don't need a key hook, you need an API hook. Then you need to write wrappers around all the exported functions of DINPUT.DLL.
The function to inject keys is called GetDeviceState(). And the code looks like this. Have a search on the web for APIHijack or for example source go here (http://www.gamedev.net/community/forums/topic.asp?topic_id=371104). FYI keybd_event() worked for Mame < 0.118.
HRESULT _stdcall CKeyboardWrapperA::GetDeviceState(DWORD cbData, LPVOID lpvData) {
int nRetVal;
int nPlayer;
BYTE *Keys;
// Get the real keyboard state.
nRetVal = m_lpDIDevice->GetDeviceState(cbData,lpvData);
Keys = (BYTE *)lpvData;
// Inject keystrokes here by altering the values of the Keys array.
//
// Example:
//
// Keys[DIK_A] = 0x80;
//
// Tells the applicatin that the 'A' key is pressed.
return(nRetVal);
}
-
Thanks headkaze, man that's a lot of code just to simulate a single keypress LOL. I still don't understand why I can't get keybd_event to work. :banghead: Oh well, time to read up on direct input. I'm also going to look into RawInput at Aaron's recommendation.
-
Thanks headkaze, man that's a lot of code just to simulate a single keypress LOL. I still don't understand why I can't get keybd_event to work. :banghead: Oh well, time to read up on direct input. I'm also going to look into RawInput at Aaron's recommendation.
If you find a way to inject keys to the raw input system of 118+ please let me know. I've had a brief look but so far have found nothing.
-
Have you tried MortScript? It's freeware.
-
Check out the release notes for 118
Changed the Windows implementation of input handling to fully
support the raw input interfaces for keyboard and mouse.
DirectInput is still used for all joystick inputs, as well as for
keyboard and mouse inputs on pre-Windows XP systems. This allows
for multiple keyboards and mice to be supported. Also changed
keyboard and mouse behavior to use non-exclusive mode in
DirectInput, and to keep the devices alive during pause for more
consistent input handling.
This means Direct Input hooking no longer works anyway. But about a week ago I figured out how to hook the Raw Input API's and inject keys. Sorry, but I won't be sharing that info on here (too much potential for abuse).
ahofle: I understand you wanted to do this so you could catch the coin drop keys then play a coin drop sample then inject the keys back in. I could write a program to do this now, but more than likely I will add it as a feature into CPWizard. If you can find some nice coin drop sounds send them to me :)
-
Cool, nice work! I only briefly looked at the Raw Input stuff and decided it wasn't worth the effort. Glad you figured it out. I'll look around for some good samples. I might also just make my own at the local arcade. I will let you know.
-
Replying to a super old post here, but I figured this out running MAME 0.212 on a Win 10 machine
Ensure you start MAME up with this option
-keyboardprovider dinput
Then you can use the Windows SendInput API using direct api key codes (instead of VK_*)
See the code on my github account if anyone is interested
https://github.com/stevetapley/mame-ai/tree/master/SendInputDemo
-
Ensure you start MAME up with this option
-keyboardprovider dinput
I just came across this through a google search and it worked and will save me so much running back and forth to my cab. Thank you!