2

I'm looking for a way to simulate a key press in an out of focus window.

More specifically, I need to press a key every x seconds in a browser page for a given amount of time. It should look like a simple key press while on the webpage without any input field selected.

I'm currently doing this with a simple AHK script, but I can't use the laptop meanwhile because I need to leave the browser's page in focus.

Do you have any ideas about that? Thank you.

edit: If it can help, there are two options in this webpage that I can select using the keys "0" and "1", and I would like to be able to select one of them while the window is minimized or in background.

  • Doesn't your script work without focus? It would be a good idea to show us this script. – harrymc Jan 9 at 21:25
  • My original script uses a simple "Send" command. I also tried ControlSend as suggested in the other answer, but it doesn't seem to fit my needs. – Francesco Villano Jan 10 at 13:05
2

Example:

Simulate a key press (send the key "a") in an (out of focus or minimized) notepad window every 2 seconds:

Loop
{
    ControlSend,, a, ahk_class Notepad
    Sleep, 2000 ; 2 seconds
}

https://autohotkey.com/docs/commands/ControlSend.htm

Instead of Loop you can use SetTimer.

  • I tried this method but it doesn't work. I'll try to be more specific: in the browser page there are two options that I can select with the keys "0" and "1"; with ControlSend I found that an option is selected only if the windows is in focus. – Francesco Villano Jan 10 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.