1

The problem

Upon pressing the left mouse button, the hotkey for Win+Z gets triggered with it (or basically any code below the LButton hotkey)


What is it?

It's an AutoHotkey toggle for a Rainmeter HUD.


The code

#If WinActive("ahk_class RainmeterMeterWindow")
~LButton::
{
Run, C:\Program Files\Rainmeter\Rainmeter.exe !Hide *
WinMinimizeAllUndo
rainystate := 0
}
#If


#z::
{
if (rainystate = 0)
{
    WinMinimizeAll
    Run, C:\Program Files\Rainmeter\Rainmeter.exe !RainmeterZPos 1 *
    Run, C:\Program Files\Rainmeter\Rainmeter.exe !Show *
    Run, C:\Program Files\Rainmeter\Rainmeter.exe !RainmeterZPos 0 "WP7\Background"
    Run, C:\Program Files\Rainmeter\Rainmeter.exe !RainmeterZPos 2 "WP7\Panels\Computer"
    rainystate := 1
}
else
{
    Run, C:\Program Files\Rainmeter\Rainmeter.exe !Hide *
    WinMinimizeAllUndo
    rainystate := 0
}
Sleep 50
Return
}

Stuff I tried

  • Moved the whole #If block in a different position
    • It ran its code, then triggered the hotkey below it
  • Tried #IfWinActive ahk_class RainmeterMeterWindow instead
    • Problem persists

What might be causing the problem

The #If statement right below the closing curly brace } (the one at line 8)



I think it's supposed to work because the AHK docs (http://l.autohotkey.net/docs/commands/_If.htm) states the following:

To turn off context sensitivity, specify #If or any #IfWin directive but omit all the parameters. For example:

#If

which was exactly what was done.

I just have no idea what exactly is the problem, other than the #If WinActive("ahk_class RainmeterMeterWindow") leaking to the code below it.

1

You are missing a Return after your first hotkey. A hotkey's code runs until it hits a Return. Your script should look like this. I've also done some formatting for you.

#If WinActive("ahk_class RainmeterMeterWindow")
    ~LButton::
        Run, C:\Program Files\Rainmeter\Rainmeter.exe !Hide *
        WinMinimizeAllUndo
        rainystate := 0
    Return   ; This was missing
#If


#z::
    if (rainystate = 0)
    {
        WinMinimizeAll
        Run, C:\Program Files\Rainmeter\Rainmeter.exe !RainmeterZPos 1 *
        Run, C:\Program Files\Rainmeter\Rainmeter.exe !Show *
        Run, C:\Program Files\Rainmeter\Rainmeter.exe !RainmeterZPos 0 "WP7\Background"
        Run, C:\Program Files\Rainmeter\Rainmeter.exe !RainmeterZPos 2 "WP7\Panels\Computer"
        rainystate := 1
    }
    else
    {
        Run, C:\Program Files\Rainmeter\Rainmeter.exe !Hide *
        WinMinimizeAllUndo
        rainystate := 0
    }
    Sleep 50
Return
2
  • Oh, thanks! Pretty careless for me there. Turns out the solution was just a single line of code. – SerinEleven Dec 28 '13 at 1:47
  • @SimonClemente Welcome to coding! – cutrightjm Dec 29 '13 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.