| Main > Software Forum |
| C programmers...what's wrong with this code? |
| << < (3/4) > >> |
| 2600:
FYI, it works fine for PS/2 keyboards if you can switch to that instead of USB. |
| ahofle:
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: --- Code: ---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]); --- End code --- 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. |
| headkaze:
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 I'm not exactly sure why the GetKeyboardState function would fail though. |
| ahofle:
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 |
| headkaze:
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. |
| Navigation |
| Message Index |
| Next page |
| Previous page |