3
I want to understand why keybd_event doesn’t work in some contexts. For example, it does not work in games with League of Legends or emulated games on ePSXe.
The following code:
Keys key = Keys.Q;
keybd_event((byte)key, 0x45, 0x0001 | 0, 0);
keybd_event((byte)key, 0x45, 0x0001 | 0x0002, 0);
Works in games like Terraria, but does not work in the games I mentioned earlier.
However, I noticed that if I try to squeeze Esc in ePSXe, it works and I am taken to the main screen. The command has activated an emulator action, but does not activate game actions. I believe the same thing happens in League of Legends.
Why doesn’t it work exactly? There is perhaps a way to make it work?
It is worth remembering that this function is native and not .Net. According to MSDN it was also exceeded by
SendInput
. http://msdn.microsoft.com/en-us/library/windows/desktop/ms646304%28v=vs.85%29.aspx This will probably not solve your "problem", as it may be related to how the application gets user data entry.– Diego C Nascimento
It is probably because the applications (games) in question must be reading the keyboard directly on the device and not using the Windows API. If they are using Directx for keyboard reading, Directx may read directly from the device. It is worth testing a simple example of Directx keyboard reading and testing your program.
– Alexandre Marcondes
@Brunolm can you clarify more context? Are you under Directx? Use XNA? Already checked the Win32 keyboard events?
– Alexandre Marcondes