IE - cant open new tab and enter new link

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DanRim
Posts: 153
Joined: 20 Jul 2018, 15:16

IE - cant open new tab and enter new link

Post by DanRim » 03 Dec 2021, 14:09

Hello,

Could some one help me with code I working on.
I want to maximize IE, open new tab, enter link www.google.com click Enter.

Problem. Then I am on any other window, desktop, sticky note, text file, word and so on I want click hotkey which minimizes that A window and maximaze only IE which is already exist, but is minimazed or not active. But script for some reasons jumps to the another window which was active and does not activate and maximize immediately IE. Script is just messing around with other active windows and does not target IE browser as I need.

I tried to use Run, www.google.com but loading is very slow, no point to use it because manually would be the same. And its open IE as another object.

So I looking for fast and relyable way at any time click hotkey and maximize IE and open website I need.

Code: Select all

SetTitleMatchMode, 2
SetKeyDelay, -1
WinMinimize, A
Sleep, 200
WinMaximize, ahk_class IEFrame
Sleep, 200
emptyVar := " "
ControlSend, Edit1,%emptyVar %, ahk_class IEFrame ; target browsers navigation input field
Sleep, 200
Send, ^t ; open new tab in IE
Send, ^a ; select all text
Send, {Backspace} ; clear text
Sleep, 200
linkVar := "www.google.com"
Clipboard := linkVar 
Sleep, 200
Send, ^v
Sleep, 300
Send, !{enter} ; ALT + Enter
Return

User avatar
mikeyww
Posts: 26891
Joined: 09 Sep 2014, 18:38

Re: IE - cant open new tab and enter new link

Post by mikeyww » 03 Dec 2021, 16:46

WinGet,...,MinMax can be used to determine a window's state.

To use %var% format, spaces would be omitted. This seems clear because your script generates an AHK error message. It's often best not to post such scripts unless your question is about the error (at least that's my own view!).

While you are testing this and working out the MinMax, I would delete the parts of the script that do not matter. It seems like your issue is selection of the right window, rather than your Send sequences.

DanRim
Posts: 153
Joined: 20 Jul 2018, 15:16

Re: IE - cant open new tab and enter new link

Post by DanRim » 03 Dec 2021, 17:15

Hi, @mikeyww, thank you for reply. All feedback is appreciated.

You talking about this part? I should not use %var%? I write like this because it is more clearly for me that it is variable.

Code: Select all

ControlSend, Edit1,%emptyVar%, ahk_class IEFrame ; target browsers navigation input field
You right, I am not sure how to select IE which exist but not active. It seems my approach WinMaximize, ahk_class IEFrame does not work properly, and I tried to minimazie some active windows because I thought it would be work around, but it does not work.

I will read documentation about WinGet, but to be honest I never used it because I not sure how to use it. By I will try. :)

User avatar
mikeyww
Posts: 26891
Joined: 09 Sep 2014, 18:38

Re: IE - cant open new tab and enter new link

Post by mikeyww » 03 Dec 2021, 17:32

Here is an example that will activate minimized windows.

Code: Select all

WinGet, ie, List, ahk_class IEFrame
Loop, %ie% {
 WinGet, state, MinMax, % winTitle := "ahk_id " ie%A_Index%
 If (state = MINIMIZED := -1)
  WinActivate, %winTitle%
}
A minimized window does not always equate to an inactive window. All windows except the active window are inactive. Some might be minimized, and some not.

DanRim
Posts: 153
Joined: 20 Jul 2018, 15:16

Re: IE - cant open new tab and enter new link

Post by DanRim » 03 Dec 2021, 18:47

@mikeyww Thank you for example, really helpful,learned new. I think I getting the idea how it should work now, but it still does not work as I need. I think it is half done.

Issue is:

Script works while the IE is minimized and it works only once. That means that IE browser was minimized and after hotkey IE is maximized and ctrl + tab was sent successfully. Now I change focus to another window, I mean, I activate manually another window and decide to run script again, for example I run script from SciTE. In this situation IE is already maximized, but not active, script activates IE and I see it from Icon in the windows menu (it changes from active window to IE browser, but for some reason script does not send Ctrl + T again.

So script works while IE browser minimized, but does not work while it is maximized, but not active.

And now for some reason I cannot open IE at all. When I trying to open IE in windows 10 it shuts down and automatically opens Edge. New issue :D
Maybe morning will be better for this challenge :D

@mikeyww I really appreciate your example :)

Code: Select all

^!p::
SetTitleMatchMode, 2
SetKeyDelay, -1
Sleep, 200

WinGet, ie, List, ahk_class IEFrame
Loop, %ie% {
 WinGet, state, MinMax, % winTitle := "ahk_id " ie%A_Index%
 If (state = MINIMIZED := -1) {
	WinActivate, %winTitle%
} else if (state = MAXIMIZED := 1) {
	WinActivate, %winTitle%
	}
}

sleep, 1000
Send, ^t ; open new tab in IE
Return

User avatar
mikeyww
Posts: 26891
Joined: 09 Sep 2014, 18:38

Re: IE - cant open new tab and enter new link

Post by mikeyww » 03 Dec 2021, 20:55

In this loop, A_Index is the iteration number. If you would like to skip the topmost matching window, you would skip the action when the A_Index value is 1. You simply need to specify the rules that you want. Another example would be that if the WinActive("A") matches the ie%A_Index%, then skip the action. This means, if the HWND of the active window equals the HWND of the window in the iteration, then skip the action.

Post Reply

Return to “Ask for Help (v1)”