WinActivate doesn't seem to work.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
PatMk
Posts: 5
Joined: 23 Apr 2021, 06:59

WinActivate doesn't seem to work.

23 Apr 2021, 07:10

Hi,

I'm trying to use the WinActivate but once it activates the window, nothing can be done.

Code: Select all

WinActivate ahk_exe brave.exe


It kind of only brings the window to the forefront and that's it. No more keys can be sent, even if I try to type something manually after the window was "activated" it doesn't respond.

As an example I wanted to switch tab after the window is activated:

Code: Select all

WinActivate ahk_exe brave.exe
WinWaitActive ahk_exe brave.exe
SendInput ^+{Tab}
What's the problem with that? Any workaround? Thank you.
User avatar
mikeyww
Posts: 26872
Joined: 09 Sep 2014, 18:38

Re: WinActivate doesn't seem to work.

23 Apr 2021, 07:47

I had no trouble with the following script.

Code: Select all

WinActivate, ahk_exe brave.exe
Send ^+{Tab}
Try only this script with no other code. Save. Reload. Close all other scripts first.
PatMk
Posts: 5
Joined: 23 Apr 2021, 06:59

Re: WinActivate doesn't seem to work.

23 Apr 2021, 09:43

Doesn't work.

I've tried with Chrome, same behavior.

That's my entire script:

Code: Select all

WinActivate ahk_exe chrome.exe
Sleep, 500
SendInput, !d ;highlight the address bar
Sleep, 50
Send, It worked
return
The window is brought to the forefront, and doesn't respond to anything I (or the script) presses on the keyboard.

The only situation I found where it's working is this: I click on the address bar of the browser, minimize the browser window and run the script - then it works. But that doesn't help me.

What is going on here? How do I make it work? Thank you.
User avatar
mikeyww
Posts: 26872
Joined: 09 Sep 2014, 18:38

Re: WinActivate doesn't seem to work.

23 Apr 2021, 10:06

You could try running the script as admin.
PatMk
Posts: 5
Joined: 23 Apr 2021, 06:59

Re: WinActivate doesn't seem to work.

23 Apr 2021, 10:11

It didn't help unfortunately. Updating AutoHotkey to the newest version also didn't help. Any other ideas? Thank you.
User avatar
mikeyww
Posts: 26872
Joined: 09 Sep 2014, 18:38

Re: WinActivate doesn't seem to work.

23 Apr 2021, 10:24

Hmm. Looks like some kind of issue relating to Chrome, but I have no further ideas. Perhaps others here can help.

Since you wrote, "doesn't respond to anything I (or the script) presses on the keyboard", I wonder why your own keyboard or key presses are not working as you expect. This would seem to point to the answer. Is your computer running other scripting software, keyboard or key managers, shortcut managers, etc.?

Since Chrome does not actually work for you even manually, was it working at some previous time?

Incidentally, KeyHistory can tell you what is happening in AHK in terms of the keys.

Your summary of the problem suggests that the issue is a different program rather than AHK, unless you have other scripts running.
19Daniel93
Posts: 40
Joined: 25 Mar 2021, 12:56
Location: La Habana, Cuba

Re: WinActivate doesn't seem to work.

26 Apr 2021, 06:25

I'm not sure but I think you have to write at the end #IfWinActive
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: WinActivate doesn't seem to work.

26 Apr 2021, 06:48

19Daniel93 wrote:
26 Apr 2021, 06:25
I'm not sure but I think you have to write at the end #IfWinActive
No. Afaics, that would have no effect here - the OP writes: "That's my entire script"
It would only affect the creation of (context-sensitive) hotkeys and hotstrings - and the original script has neither of these; and if you write it at the end, it would only affect other, following hotkeys anyway.
User avatar
rommmcek
Posts: 1473
Joined: 15 Aug 2014, 15:18

Re: WinActivate doesn't seem to work.

26 Apr 2021, 08:26

Try:

Code: Select all

;pa(GetAltTabWindows()) ;aux. just to see the Z-order
WinActivate, ahk_exe brave.exe
WinWaitActive, ahk_exe brave.exe,, .1 ; try to comment this line out too
WinActivate % "ahk_id " GetAltTabWindows().1
Send ^+{Tab}
Return

GetAltTabWindows() { ; teadrinker https://www.autohotkey.com/boards/viewtopic.php?p=344440#p344440
   AltTabList := []
   WinGet, list, List
   Loop % list
      if IsAltTabWindow(list%A_Index%)
         AltTabList.Push(list%A_Index%)
   Return AltTabList
}

IsAltTabWindow(hWnd) {
   static GA_ROOTOWNER := 3, WS_EX_APPWINDOW := 0x40000, WS_EX_TOOLWINDOW := 0x80, DWMWA_CLOAKED := 14
   if !DllCall("IsWindowVisible", "Ptr", hWnd)
      Return false
   
   hOwner := DllCall("GetAncestor", "Ptr", hWnd, "UInt", GA_ROOTOWNER, "Ptr")
   hPopup := DllCall("GetLastActivePopup", "Ptr", hOwner, "Ptr")
   if (hOwner = hWnd && hPopup != hWnd)
      Return false
   
   WinGet, exStyles, ExStyle, ahk_id %hWnd%
   ;if (exStyles & WS_EX_TOOLWINDOW) && !(exStyles & WS_EX_APPWINDOW)
   if (exStyles & 0x8000088) ; WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE
      Return false
      
   DllCall("DwmApi\DwmGetWindowAttribute", "Ptr", hWnd, "UInt", DWMWA_CLOAKED, "UIntP", cloaked, "UInt", 4)
   Return !cloaked
}

pa(in) {
    MsgBox % txtArr(in)
}

txtArr(r, i:="  ", d:=0, b:="") {
	For k, v in (r, IsObject(r)? "": e:= 1)
		c.= IsObject(v)? b k ":`n" txtArr(v, i, d+1, b i): b k ": " v "`n", d>0? "": t:=c
    Return e? r: d>0? c: t
}


Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RussF and 368 guests