post #1 of 1
Thread Starter 
Hi guys! Trying to write an AHK script and my if statements don't seem to be working. The objective of this particular section is:
- When the shortcut (eg. Caps+c) is pressed, switch to the window if it exists
- Else, create a chrome window

Now the switching works but the second half of the statement involving the creation of a window doesn't. Its not a problem with the window creation because if I swap them it works.

This is all relevant code:
Code:
;Capslock modifier
        $*Capslock:: ; when capslock is pressed create an invisible window
        press :=  ; clear press variable
        Gui, 99:+ToolWindow
        Gui, 99:Show,NoActivate x-1 w1 , Capslock Is Down
        keywait, Capslock
        Gui, 99:Destroy ; destroy window when capslock is released
        if (press = "" ){ ; if a hotkey was not pressed, toggle CAPSLOCK
                SetCapsLockState, % (State:=!State) ? "On" : "Off"
        }       
        return

;Move to window
        ToggleWinMinimize(TheWindowTitle)
        {
        SetTitleMatchMode,2
        DetectHiddenWindows, Off
        IfWinActive, %TheWindowTitle%
        {
        WinMinimize, %TheWindowTitle%
        }
        Else
        {
        IfWinExist, %TheWindowTitle%
        {
        WinGet, winid, ID, %TheWindowTitle%
        DllCall("SwitchToThisWindow", "UInt", winid, "UInt", 1)
        }
        }
        Return
        }

#IfWinExist Capslock Is Down  ; enable the following hotkeys while invisible Capslock window exists
        ;App launch
        c::
        IfWinExist, %chrome%
        {
                ToggleWinMinimize("Google Chrome")
                press = true
                return
        }
        else
        {
                Run "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
                press = true
                return
        }
#IfWinExist

Any ideas?
The Stormtrooper
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k @ 4.0 Ghz Asrock Z77 Extreme4 Gigabyte GTX 970 G.Skill Ripjaws-X 8g Kit (4Gx2) DDR3 1600 
Hard DriveHard DriveCoolingOS
Samsung 830 Series 128GB SSD A crap tonne of other misc hard drives Cooler Master Hyper 212 EVO Windows 10 Home 
MonitorKeyboardPowerCase
HP w2207h More than 1, less than 10, all mechanical Corsair TX 750M NZXT Phantom 410 White 
MouseMouse PadAudio
Razer Deathadder 2013 Steelseries QCK+ Asus Xonar DX 
  hide details  
Reply
The Stormtrooper
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k @ 4.0 Ghz Asrock Z77 Extreme4 Gigabyte GTX 970 G.Skill Ripjaws-X 8g Kit (4Gx2) DDR3 1600 
Hard DriveHard DriveCoolingOS
Samsung 830 Series 128GB SSD A crap tonne of other misc hard drives Cooler Master Hyper 212 EVO Windows 10 Home 
MonitorKeyboardPowerCase
HP w2207h More than 1, less than 10, all mechanical Corsair TX 750M NZXT Phantom 410 White 
MouseMouse PadAudio
Razer Deathadder 2013 Steelseries QCK+ Asus Xonar DX 
  hide details  
Reply