what am I doing wrong with this HK that is stopping hotstrings

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Kellyzkorner_NJ
Posts: 84
Joined: 20 Oct 2017, 18:33

what am I doing wrong with this HK that is stopping hotstrings

29 Apr 2022, 16:21

I've had the below in my script for years. Yesterday I was trying to include a couple other scripts to lessen my icon burden in tray and it didn't work so I un-included them. Somewhere in the process some of my hotstrings stopped working and I don't know why. I isolated it to this (which had begun acting up in and of itself anyway). I started with #if and ended with #if and a couple others for good measure in case I forgot any above it. I moved this to the very bottom and it works as expected now but do you see anything that I did with this that would cause this? I believe I'm running 1.1.33.01 U32. Thanks in advance.

Code: Select all

;############BROWSER BACK START##########
#If WinExist("- Google Chrome") and MouseIsOver("- Google Chrome") or WinExist("- Mozilla Firefox") and MouseIsOver("- Mozilla Firefox") or WinExist("Opera") and MouseIsOver("Opera")

MButton:: ; <-- Go Back, Browser Back
If MouseIsOver("Mozilla Firefox")
{
;Msgbox, 0, 0, Firefox Undo Closed Tab - Using XButton1 The Mouse is over Firefox, .4
Winactivate Mozilla Firefox
WinWaitActive Mozilla Firefox
Sleep 150
Send {BS}
Return
}
Else
;IfwinActive Opera
If MouseIsOver("- Opera")
{
;Msgbox, 0, 0, Opera Undo Closed Tab If Mouse is Over , 0.4
Winactivate Opera
WinWaitActive Opera
Sleep 150
Send {ALTDOWN}{Left}{ALTUP}
Return
}
Else
If MouseIsOver ("- Google Chrome")

{ 
;Msgbox, 0, 0, Opera Undo Closed Tab If Mouse is Over chrome, 1
; Winactivate ahk_class Chrome_WidgetWin_1
; WinWaitActive ahk_class Chrome_WidgetWin_1
WinActivate Google Chrome
WinWaitActive Google Chrome
Sleep 250
Send !{Left}
Return
}
Else
Return
#If
#IfWinExist
#If Winexist
#iftimeout
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: what am I doing wrong with this HK that is stopping hotstrings

29 Apr 2022, 17:17

It looks like you need the following at the top of your script:

Code: Select all

SetTitleMatchMode, 2
User avatar
Kellyzkorner_NJ
Posts: 84
Joined: 20 Oct 2017, 18:33

Re: what am I doing wrong with this HK that is stopping hotstrings

01 May 2022, 12:16

Thanks Boiler. Here are the first four lines of my script.

#SingleInstance force
#Persistent
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SetTitleMatchMode, 2

So I'm guessing it's not that. And the hotstrings and hotkeys above this particular code I posted originally work. I had it in the middle (had been working previously so I don't understand what caused this really), and from below it when it was at that position, strings and keys stopped as if invisible. As if I had not ended with the #If etc, and it still considered everything below it conditional. So weird.
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: what am I doing wrong with this HK that is stopping hotstrings

01 May 2022, 13:12

Kellyzkorner_NJ wrote: As if I had not ended with the #If etc, and it still considered everything below it conditional. So weird.
Actually it's not so weird. It's one of the directives that you put at the bottom that is weird and is causing the problem. For one thing, you don't need several types of bare #If directives to end the prior condition. One bare #If stops the last condition (which would be the only one that would still apply) no matter if the prior one were an #If or an #IfWin... type of directive.

And because #IfTimeout isn't a condition and doesn't belong there (which happens not to make sense anyway since it is not followed by a value), the last one you put is #If Winexist. So that's the one that will apply to all the hotkeys that follow it. And the condition on that directive evaluates as false, making all hotkeys below it inactive. You in essence made a directive that says #If False. Perhaps you meant it to be #IfWinExist, but you already had one before it, so I'm not sure why you would try to repeat it. But in any case, the reason #If Winexist evaluates as false is that Winexist is not a call to the WinExist() function or anything like that. It's just a variable named Winexist, which has a null value since you didn't assign anything to it, making the condition false.

Bottom line is that you should remove the last three lines of what you posted:

Code: Select all

#IfWinExist
#If Winexist ; THIS LINE IS THE PROBLEM
#iftimeout
...leaving just:

Code: Select all

#If
User avatar
Kellyzkorner_NJ
Posts: 84
Joined: 20 Oct 2017, 18:33

Re: what am I doing wrong with this HK that is stopping hotstrings

11 May 2022, 20:18

@boiler Thanks so much and thanks for the great explanation. I thought I was ending a Winexist and not starting one there. I added the others in case I had left one earlier up (the script is 58,000 lines long) that I missed, and figured I'd try to add others. I appreciate your help.

Kelly
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: what am I doing wrong with this HK that is stopping hotstrings

11 May 2022, 20:37

You’re welcome.

To be clear: You’re not starting a new WinExist. You’re staring a new #If because you followed it with a variable (WinExist). There is no such thing as starting a new WinExist. You could start or end an #IfWinExist, but what you did is start a new #If with a false condition because WinExist by itself (i.e., with a space after the #If) is nothing but an empty variable.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, peter_ahk and 330 guests