to many curly brackets when there isn't? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
fizzle6325
Posts: 12
Joined: 06 Jul 2023, 21:50

to many curly brackets when there isn't?

Post by fizzle6325 » 22 May 2024, 16:51

Hello, I'm a little embarrassed to ask this because i feel the answer is staring me in the face, but weeding thru all the V1 matches in google is getting exhausting. ( i do use search operators)
so i understand in V2, that all blocks of code need the curly brackets. I'm using VScode so it's clear to see what brackets are associated w/ it's counter part but it keeps telling me i have to many. (unexpected })
I am def struggling w/ the change over to V2. it would be nice if there was a collective whole, a sorta portal to search the internet thru were users could flag scripts on the open internet.

all i'm trying to do is. if you hold the right mouse button while firefox is active it minimizes notepad it maximized and visa/versa, and also open it if it not. i tried putting a # in front of hotifwinactive. that didn't work.

Code: Select all


~RButton::{
Duration := 0
Loop while GetKeyState("Rbutton","P"){

	Duration++
	If Duration > 5 {

            If WinExist(wTitle := "Notepad") {
                
                If WinActive(wTitle){
                WinMinimize
                break
                }

                Else {
                WinActivate
                break
                }

            Else {
            Run ("Notepad.exe")
            break
            }
            
            }   
    }
    else{
    Sleep(100)
    }
}
}
[Mod edit: Fixed code tags - which should go around the code.]

side question: does "WTitle := "Notepad" carry over to WinMinimize or does that need to be declared everytime? (does it set that dedicated variable)
any help is appreciated. thank you.

fizzle6325
Posts: 12
Joined: 06 Jul 2023, 21:50

Re: to many curly brackets when there isn't?

Post by fizzle6325 » 22 May 2024, 17:05

forgot to add the lines above the code.

Code: Select all

SetTitleMatchMode 2
DetectHiddenWindows true

HotIfWinActive "ahk_exe firefox.exe"

niCode
Posts: 319
Joined: 17 Oct 2022, 22:09

Re: to many curly brackets when there isn't?

Post by niCode » 22 May 2024, 17:17

HotIf refers to hotkeys created with the Hotkey function. For regular hotkeys, use the directive #HotIf. Loop while isn't a loop. loop is and while is but not both. Also, you have an out-of-place else statement. Two else's in a row doesn't make sense.

Try this:

Code: Select all

#HotIf WinActive('ahk_exe firefox.exe')
~RButton::{
    if not KeyWait('RButton', 'T0.5') {
        if WinExist('Notepad') {
            switch WinGetMinMax() {
                case  1: WinMinimize()  ; if maximized, minimize
                case  0: WinMinimize()  ; if neither, minimize
                case -1: WinMaximize()  ; if minimized, maximize
            }
        } else {
            Run('Notepad.exe')
        }
    }
}
#HotIf

fizzle6325
Posts: 12
Joined: 06 Jul 2023, 21:50

Re: to many curly brackets when there isn't?  Topic is solved

Post by fizzle6325 » 22 May 2024, 18:17

that worked, you da man.

i really like how you included the all possible states. also much cleaner. and thank you for clarifying my other mistakes.

Post Reply

Return to “Ask for Help (v2)”