0

This script is working fine when I run it in the foreground with Send and MouseClick instead of ControlSend and ControlClick (and wb.Visible = true). What is the issue here with running it in the background?

code1           := "foobar"
url             := "https://app.powerbi.com/groups/me/reports/xxx"
wb              := ComObjCreate("InternetExplorer.Application")     ;create com object  
wb.Visible      := false                            ;true to show IE
wb.Navigate(url)

while (wb.busy)                                     ;wait while page loads
    sleep 10

ControlSend,, {LWin down}{Up down}
ControlSend,, {LWin up}{Up up}

sleep 20000

ControlClick, left, 1275, 320
sleep 3000
ControlClick, left, 1275, 510
sleep 500
ControlClick, left, 2200, 1380
sleep 3000
ControlClick, left, 2200, 1380
sleep 3000
ControlClick, left, 2200, 1380
sleep 120000
ControlClick, left, 2760, 2000
sleep 500
ControlClick, left, 2760, 2000
sleep 5000
ControlClick, left, 2760, 2000
sleep 3000
ControlClick, left, 2760, 2000
1
  • Since AHK only works through the mouse and keyboard input methods of Windows, and all of them only ever apply to an active window (or the desktop) you cannot use AHK to send any keyboard or mouse actions to a window in the background. Even accessing the fields with the IE COM object means having the page visible (but doesn't have to be active). I mean, you have the page already in the object, just use getElementById(), getElementsByName(), getElementsByTagName() and then .focus(), .click() or .value= to do what you want. Commented Nov 9, 2020 at 19:48

1 Answer 1

1

DetectHiddenWindows, On directive can detect a window running in the background.

Keystrokes and strings can be passed to hidden or inactive windows. for example, the snippet below starts notepad.exe, sends a message "sending a string to the notepad.exe" even though notepad is running in the background.

#SingleInstance, Force 

DetectHiddenWindows, On

Run, Notepad, , Hide      ; run notepad in the background
if WinExist("ahk_class Notepad")
    ControlSend, Edit1, sending a string to the notepad.exe, Untitled

; verify: wait for 2s to see the effect
sleep 2000
WinShow

Similarly for your problem, it will hopefully work (can't test, don't have powerbi account)

DetectHiddenWindows, On

code1           := "foobar"
url             := "https://app.powerbi.com/groups/me/reports/xxx"
wb              := ComObjCreate("InternetExplorer.Application")     ;create com object  
wb.Visible      := false                            ;true to show IE
wb.Navigate(url)

while (wb.busy)                                     ;wait while page loads
    sleep 10

if WinExist("ahk_class IEFrame")
    ;MsgBox % "hidden window id = " . WinExist("A")
    ControlSend,, {LWin down}{Up down}
    ControlSend,, {LWin up}{Up up}
    sleep 20000
    ControlClick, left, 1275, 320
    sleep 3000
    ControlClick, left, 1275, 510
    sleep 500
    ControlClick, left, 2200, 1380
    sleep 3000
    ControlClick, left, 2200, 1380
    sleep 3000
    ControlClick, left, 2200, 1380
    sleep 120000
    ControlClick, left, 2760, 2000
    sleep 500
    ControlClick, left, 2760, 2000
    sleep 5000
    ControlClick, left, 2760, 2000
    sleep 3000
    ControlClick, left, 2760, 2000
Sign up to request clarification or add additional context in comments.

Comments

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.