PostMessage & WM_KEYDOWN

425 views
Skip to first unread message

李浩

unread,
May 6, 2021, 6:26:34 AM5/6/21
to Java Native Access
HWND hWnd0 = User32.INSTANCE.FindWindow(null, "雷电模拟器(64)");
HWND hWnd1 = User32.INSTANCE.FindWindowEx(hWnd0, null, "RenderWindow", null);

// Hold 'W' key
User32.INSTANCE.PostMessage(hWnd1, WinUser.WM_KEYDOWN, new WPARAM(0x57), new LPARAM(0)); 

// That is works, but the game character only moves forward a bit
// Shouldn't the meaning of'WinUser.WM_KEYDOWN' mean holding down all the time?
// How do I keep holding down the'W' key until I call the'keyUp' method

Durchholz, Joachim

unread,
May 6, 2021, 6:34:49 AM5/6/21
to jna-...@googlegroups.com

It’s just the way Microsoft defined how WM_KEYDOWN should work.

See https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-keydown for full details.

https://docs.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input explains under what circumstances Windows sends what WM_KEY messages, and any library code that accepts keyboard data will expect that, so you should take care that you replicate Windows’ behaviour as exactly as possible.

 

(The other approach might be to directly call the “move the character code” instead of going through sending a message. If that’s a viable option for your use case, you’ll have far less moving parts that may affect how your code works.)

 

Regards,

Jo

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/15154c15-2812-46df-9e9e-abe2533b516cn%40googlegroups.com.

 

Sensitivity: C2 Internal

The content of this e-mail is intended only for the confidential use of the person addressed.
If you are not the intended recipient, please notify the sender and delete this e-mail immediately.
Thank you.

Reply all
Reply to author
Forward
0 new messages