Main > Software Forum

C programmers...what's wrong with this code?

(1/4) > >>

ahofle:
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. 


--- Code: ---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;
}

--- End code ---

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. 

headkaze:
I would try a test something along the lines of:


--- Code: ---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;
}
--- End code ---

Just to see if you can get them blinking okay.

The following link also might be helpful http://www.codeproject.com/cpp/togglekeys.asp

shorthair:
Looks like someone needs to create a front-end to simply assign what pulse values, etc, to where.

ahofle:

--- Quote from: headkaze on June 04, 2007, 02:21:37 pm ---Just to see if you can get them blinking okay.

The following link also might be helpful http://www.codeproject.com/cpp/togglekeys.asp


--- End quote ---

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.

2600:

--- Quote from: ahofle on June 04, 2007, 04:20:41 pm ---
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.

--- End quote ---

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.

Navigation

[0] Message Index

[#] Next page

Go to full version