0
votes

My if statement on line 8 isn't working. Even though the Msgbox of %Width% shows 3200 I always get the "width is not 3200" message box. Changing the if to == and putting checking for "3200" rather than 3200 has no effect.

I've also put the if statement inside the activeMonitorInfo method and it shows the same behaviour in there.

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

activeMonitorInfo( X, Y, Width, Height ) 
Msgbox %Width%

if ( %Width% = 3200 ) {
    msgbox "Width is 3200"
    return
} else {
    msgbox "Width is not 3200"
    return
}

activeMonitorInfo( ByRef X, ByRef Y, ByRef Width, ByRef Height )
{
    CoordMode, Mouse, Screen
    MouseGetPos, mouseX , mouseY
    SysGet, monCount, MonitorCount
    Loop %monCount%
    {   
        SysGet, curMon, Monitor, %a_index%
        if ( mouseX >= curMonLeft and mouseX <= curMonRight and mouseY >= curMonTop and mouseY <= curMonBottom ) {
                X      := curMonTop
                y      := curMonLeft
                Height := curMonBottom - curMonTop
                Width  := curMonRight  - curMonLeft
                return
        }
    }
}
1

1 Answers

1
votes

Omit the percent signs:

if ( Width = 3200 ) {

Same as

if width = 3200
{

same as

if(width=="3200") {

but for some reasons, if width == 3200 or if width = "3200" will not work. I simply only use the very first method above, nothing can go wrong there.

In Ahk, you only need %s if the documentation explicitly asks you for a value (or name, text, number, etc.).

Also, use percent signs in literal assigments: a = %width%. However, not when you use the expression assignment: a := width.