The NEW Build Your Own Arcade Controls
Main => Software Forum => Topic started by: ahofle on June 04, 2007, 12:36:54 pm
-
I recently upgraded my OS on my MAME cab from Win98 to WinXP and now the ledutil.exe utility that blinks the keyboard LEDs (or in my case my player one and two start buttons) is not working correctly. I think the problem is in this snippet of code from ledutil.c for USB keyboards, but I am not seeing anything really wrong. Basically what is happening is that when you insert a coin in MAME, the numlock LED blinks at about half the rate it should. Then when you insert a 2nd coin, the capslock LED blinks at the correct rate, but the numlock LED stops blinking altogether.
case LED_METHOD_USB:
{
static const BYTE vk[3] = { VK_NUMLOCK, VK_CAPITAL, VK_SCROLL };
BYTE keyState[256];
int k;
GetKeyboardState((LPBYTE)&keyState);
for (k = 0; k < 3; k++)
{
if ((((state >> k) & 1) && !(keyState[vk[k]] & 1)) ||
(!((state >> k) & 1) && (keyState[vk[k]] & 1)))
{
// Simulate a key press
keybd_event(vk[k], 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
//SendRawKey(vk[k],KEYEVENTF_EXTENDEDKEY);
// Simulate a key release
keybd_event(vk[k], 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
//SendRawKey(vk[k],KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP);
}
}
break;
}
Here's the MSDN for keybd_event:
http://msdn2.microsoft.com/En-US/library/aa453245.aspx
I'm not sure what the 0x45 scan code value is for. I doubt mamedev has much interest in maintaining this as they pulled it out of the MAME code and put it into its own utility because it was considered a hack.
-
I would try a test something along the lines of:
case LED_METHOD_USB:
{
keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
keybd_event(VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
keybd_event(VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
keybd_event(VK_SCROLL, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
keybd_event(VK_SCROLL, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
break;
}
Just to see if you can get them blinking okay.
The following link also might be helpful http://www.codeproject.com/cpp/togglekeys.asp
-
Looks like someone needs to create a front-end to simply assign what pulse values, etc, to where.
-
Just to see if you can get them blinking okay.
The following link also might be helpful http://www.codeproject.com/cpp/togglekeys.asp
Thx I'll try that when I get home. I can't figure out how to compile this thing as a console app. Then I could do some printf debugging. :( Unfortunately it just runs in the background so any console output is lost.
-
Thx I'll try that when I get home. I can't figure out how to compile this thing as a console app. Then I could do some printf debugging. :( Unfortunately it just runs in the background so any console output is lost.
IIRC, edit windows.mak and take out the -mwindows for ledutil. While you are at it you should turn the debug on in ledutil.c
I briefly looked at the bug a while ago, but didn't see anything obvious. The ledutil keyboard code was the exact same code as the code when it was in MAME. Post if you find anything. I believe Headkaze posted some good software a while ago so that you can view all the messages being passed as well.
-
Yeah I posted a version of ledutil as a console app..
http://forum.arcadecontrols.com/index.php?topic=62566.0
You can also check out MameInterop SDK, but I doubt it would be very helpful for your needs.
http://forum.arcadecontrols.com/index.php?topic=62982.0
There is also Howards Mame Hooker that might be worth a look, although his website is down, someone posted a link to it on this forum.
-
MameInterop SDK is the one I was talking about. I found it pretty useful when debugging ledutil to see what messages were being passed from MAME.
-
Thanks for the info, guys. Now if I can just get some free time at home to mess with this! I will post here if/when I find anything. I really want my player 1/2 start buttons to blink like before so I do have some motivation for this. :banghead:
-
You could always get yourself an LED controller and use MameInterop to make your actual buttons light up instead of keyboard LED's. Much cooler IMHO.
-
Yeah, I know. I'm trying to avoid spending any additional money though (and I only need two LEDs to blink), plus the fact that this used to work perfectly before I upgraded really irks me.
-
FYI, it works fine for PS/2 keyboards if you can switch to that instead of USB.
-
Well it seems the problem is not with keybd_event at all, but rather with the GetKeyboardState call that is before it. It's not returning the correct state after the previous keybd_event calls toggles the leds -- it's always 0. The net result is that the blinking is twice as slow. Adding these lines after the keybd_event 'for' loop to manually SetKeyboardState saves it correctly for next time:
keyState[VK_NUMLOCK] = (keyState[VK_NUMLOCK] & ~1) | ((state >> 0) & 1);
keyState[VK_CAPITAL] = (keyState[VK_CAPITAL] & ~1) | ((state >> 1) & 1);
keyState[VK_SCROLL] = (keyState[VK_SCROLL] & ~1) | ((state >> 2) & 1);
SetKeyboardState(&keyState[0]);
The blinking works correctly with this change. I'm still having issues with it picking up the correct initial state when MAME starts however, but at least progress has been made. EDIT: Nevermind, the initial state seems to be working too. So it appears those 4 lines fix all the issues. I'll post on mametesters forums.
-
Perhaps you could try GetKeyState instead. It takes the virtual key code as it's parameter.
So it would look something like..
GetKeyState(vk[k]);
More on that at MSDN GetKeyState Function (http://msdn2.microsoft.com/en-us/library/ms646301.aspx)
I'm not exactly sure why the GetKeyboardState function would fail though.
-
I'm not sure either, but I'm guessing the keybd_event call isn't affecting the GetKeyboardState for the local ledutil thread for whatever reason. So the call to SetKeyboardState saves it for next time (but doesn't blink the LEDs), and the keybd_event call toggles the LEDs. :dunno
-
I don't see a SetKeyboardState call there, but I'm not looking at the full source. GetKeyboardState reads the actual status of the Caps Lock / Scroll Lock / Numlock keys. Then they are toggled using keybd_event(). There is no need to call SetKeyboardState.
-
I had to add the SetKeyboardState call. If you don't call it, then GetKeyboardState() always returns 0 for numlock/capslock/scrolllock.
-
You guys do know that ledutil has command line options don't you? The three "modes" that used to be in the mame.ini, one of them should be passed when launching the exe. All should work fine, even in xp. :)
-
USB mode didn't work fine until last night. :)
If you put one coin in, it blinks at half the rate it should. If you put in a 2nd coin, the numlock stops blinking altogether and capslock blinks normally.
MAME testers thread (http://www.mameworld.info/ubbthreads/showthreaded.php?Cat=&Number=105975&page=0&view=collapsed&sb=5&o=&fpart=1&vc=1&new=1181049173)