I've made an interface to a NES Controller with an atxmega, which send the keys through serial. The problem lies in the program that reads the input and sends keybd_events accordingly.
if(szBuff[0] & BTN_LEFT) {
keybd_event(VkKeyScan('j'), 0, 0, 0);
keybd_event(VkKeyScan('j'), 0, KEYEVENTF_KEYUP, 0);
}
Problem is, it fails to get recognized as a 'j' in a NES emulator, while it does so in say a br开发者_如何学JAVAowser.
Hard to answer this without you explaining how the Nintendo emulator works. But you'll have to provide the virtual key code to VkKeyScan(). Which is 'J', not 'j'. As long as the Shift key isn't pressed, Windows will translate that to a WM_CHAR message that generates a 'j'.
Note that keybd_event() takes a virtual key and a scan code. You are passing the scan code as the virtual key. Fix:
keybd_event('J', VkKeyScan('J'), 0, 0);
精彩评论