Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Java to send simulated Windows keyboard events to a C program that uses SDL

Tags:

java

keyboard

sdl

I have a C program that gets events from the keyboard just fine. However, I want to use Java to send it simulated keyboard events. I have tried two approaches:

  1. Use the Robot class
  2. Call the keybd_event function in win32.dll (native).

Both the above approaches will do things like send keys to a text editor, etc. but the other program (GIMX to be exact) won't recognize the events. Any idea why this would be, and what I could do to get Java to communicate with it?

like image 608
user1292066 Avatar asked Nov 14 '22 08:11

user1292066


1 Answers

See here for a related discussion:

http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/29cf2de9-412e-44dd-9050-174089d8e2a2/

Essentially, it looks like you need to send low-level SendInput events, i.e. scan codes to work with DirectInput. To use scan codes, pass KEYEVENTF_SCANCODE in your KBDINPUT structure and pass the scan code in wScan.

  • http://msdn.microsoft.com/en-us/library/windows/desktop/ms646271(v=vs.85).aspx
like image 195
Ben Avatar answered Nov 16 '22 03:11

Ben