I'm trying to send a key to a window, which is simple enough and I managed to do before, but I'd prefer if it could send a key even when the window is inactive,
and I would like to pick which window to send the key to when the script starts, because I'd have multiple instances of this game open, and I'd need to select the one I need the script on, and no other.
That being said, it shouldn't be that hard with ControlSend, but I'm not sure on how to proceed. I explained a bit more in the code itself.
Code: Select all
SetTimer, Routine, 10000 ; I need a portion of code that detects the ahk_id of the window I want, and returns the value to the variable MYWINDOW in this case. Or whatever other name. ; I'm looking into winexist, please do tell if there's a better way. ; Basically I'd need something like mywindow := *code that checks ahk_id of the window I'm hovering, or better, that I press a key on/in.* ; The end result should send the key "3" every 10 seconds to that specified window/ahk_id. ; I copied the routine bit from an old ahk forum thread (forgot which one now), the "inside" of the routine is my code. id := WinExist(%MYWINDOW%) Routine: ControlSend,, 3, ahk_id %id% return F12:: ; or any other key if f12 is problematic SetTimer, Routine, off return
Thanks in advance.
TL;DR: function that, when a specific key is pressed, detects the ahk_id of the window on focus, to be able to send keystrokes to it even when it becomes inactive or unfocused, while having another copy of that game open that DOESN'T receive the keystrokes.