user2103615
user2103615

Reputation: 11

How to simulate key press on a background window

I need to force Outlook which is in the background, to check for new emails every 2 seconds. So I wrote a following script but it doesn't do it. What's wrong? I don't want the script to disturb what I do and give the focus to the Outlook window. The "ahk_class rctrl_renwnd32" is correct, I checked it with "WinActivate, ahk_class rctrl_renwnd32" and it worked.

Loop
{
    ControlSend,, {F9}, ahk_class rctrl_renwnd32
    Sleep 2000 ; Wait 2 seconds
}

Upvotes: 1

Views: 4744

Answers (1)

Robert Ilbrink
Robert Ilbrink

Reputation: 7953

There is no error in your code. The problem might be in the receiving application. When I test this in Notepad, an F5 (Print time & date) is executed when the Notepad window is open somewhere on my second screen. As soon as I minimize Notepad, it will no longer execute F5, but it still accepts a string like A{Enter}B{Enter}C{Enter} when minimized.

!q::
ControlSend,, {F5}A{Enter}B{Enter}C{Enter}, ahk_class Notepad
Return

Solution, Try if this works when you keep the window on screen somewhere (no need to have the focus).

I have used Outlook in the past and remember that F9 took some time to execute. Running this every 2 seconds looks like overkill. If getting your e-mail in time is THAT important that you are willing to "kill" the mail server with refresh requests, I would discuss a solution with your IT support.

Upvotes: 1

Related Questions