2

I want to send a keystroke to chrome, but it only works while the window is active. I'd like this to work even when the window is in the background.

;begin
Pause
Loop {
ControlSend,,{escape}, Omegle - Google Chrome
Sleep 2650
}
F9::Pause
;end
1
  • Don't have a full example but you probably need to use PostMessage instead of ControlSend. PostMessage can start a window by it's handle, whereas ControlSend is closer to emulating the user pressing a key - which relies on the currently focused window. Commented Aug 28, 2015 at 0:16

1 Answer 1

1

To operate upon a control's HWND (window handle), leave the Control parameter blank and specify ahk_id %ControlHwnd% for the WinTitle parameter (this also works on hidden controls even when DetectHiddenWindows is Off). The HWND of a control is typically retrieved via ControlGet Hwnd, MouseGetPos, or DllCall.

From http://ahkscript.org/docs/commands/ControlSend.htm

Sign up to request clarification or add additional context in comments.

9 Comments

yeaaaaah I have no idea how to do that. The best I could come up with was: ControlGet, ControlHwnd, Hwnd,,, Omegle - Google Chrome ControlSend,,{escape}, ahk_id %ControlHwnd%
That should be it according to the docs. Any errors or just not working?
Just doesn't work. But it works fine when I actually tab INTO the window. In other words, controlget is working (I think), but it's for whatever reason only working when I tab back into chrome.
Oh nvm it doesn't work. For whatever reason it doesn't loop now.
Maybe chrome doesn't accept the escape key at the global window level, maybe it needs to target a specific tab control or something like that. I'm not on windows right now so can't really test. Try to set a breakpoint and inspect the ControlHwnd variable and see if it's being grabbed correctly. Try it without the loop at first.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.