I've dug into this topic for the past few days and all I got not working at all (it works in Notepad but in my case it's not).
The SendMessage
, PostMessage
or SendInput
function only work when I active the game window. So, this is not the behavior that I expected. Then I found this guide in a game he can send key to a game (F1) w/o activating the game window using assembly code injector. Check the source here in 4:30 ++
So base on that guide there're 2 things I need to send a keystroke into an inactive window:
- Find the assembly code of the game on memory that do press key for us
- Using some libraries to make it run (I'm testing with Python now)
Let's say I can easily find the assembly code needed in step 1. For example, like in the video:
push 0x70 // Send F1
push 0x100 // Send keydown
mov eax 0x006BEEFA8
call 0x01048270
push 0x70 // Send F1
push 0x100 // Send keyup
mov eax 0x006BEEFA8
call 0x01048270
I found that in Python I can use pywin32
lib to create new address using VirtualAllocEx
but have no idea how to put this code (in step 1) into this new address that I've just created. Any examples or book about this would be helpful to solve my issue.
I tried to send keystroke into an inactive game window w/o activating it using read write memory process.
I don't want to call SetForgroundWindow()
it probably works but it's not my purpose, I need to do other tasks while the script running in a specific window in the background.