Page 1 of 1

#Include scripts breaks

Posted: 19 Jan 2018, 11:00
by micnolmad
Hi, I need a bit helping guys. I have, maybe not zero skills i ahk but definitely max level 1!

I have three scripts I run always, which I have just search the forums. I do not want three icons but just one so I included them in one script but that breaks one of them, namely AHK_HideMouseOnIdle. The scripts works just fine on it's own so I am thinking I need better separation. I just don't know how or even if that is it. So if one of you guys can see where the issue is, I would be grateful.

These are the scripts:

Code: Select all

#Include AutoHotKey\AHK_HideMouseOnIdle.ahk
#Include AutoHotKey\AHK_TurnScreenOff.ahk
#Include AutoHotKey\AHK_WindowsSystemKBSC.ahk

Code: Select all

#Persistent

CoordMode, Mouse, Screen
MouseGetPos, ix, iy

SystemCursor("Init")

SetTimer, CheckIdle, 250
return

CheckIdle:
MouseGetPos, cx, cy
TimeIdle := A_TimeIdlePhysical // 1000
if (TimeIdle >= 3)
{
    MouseGetPos, ix, iy
    SystemCursor("Off")
}
else if (cx != ix or cy != iy)
{
    SystemCursor("On")
}
return

OnExit, ShowCursor  ; Ensure the cursor is made visible when the script exits.
return

ShowCursor:
SystemCursor("On")
ExitApp

SystemCursor(OnOff=1)   ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
    static AndMask, XorMask, $, h_cursor
        ,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
        , b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13   ; blank cursors
        , h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13   ; handles of default cursors
    if (OnOff = "Init" or OnOff = "I" or $ = "")       ; init when requested or at first call
    {
        $ = h                                          ; active default cursors
        VarSetCapacity( h_cursor,4444, 1 )
        VarSetCapacity( AndMask, 32*4, 0xFF )
        VarSetCapacity( XorMask, 32*4, 0 )
        system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
        StringSplit c, system_cursors, `,
        Loop %c0%
        {
            h_cursor   := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
            h%A_Index% := DllCall( "CopyImage",  "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
            b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
                , "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
        }
    }
    if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
        $ = b  ; use blank cursors
    else
        $ = h  ; use the saved cursors

    Loop %c0%
    {
        h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
        DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
    }
}

Code: Select all

; Win+M will turn off the screen. 0x112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER.
#m::
Sleep 1000
SendMessage, 0x112, 0xF170, 2,, Program Manager
return

Code: Select all

#Ins::#Pause

Re: #Include scripts breaks

Posted: 19 Jan 2018, 12:49
by gregster
Just add the code of your two small hotkey scripts (2 and 3 above) to the end of AHK_HideMouseOnIdle.ahk . No need to #include them. That's what #include does, anyway.

(Without testing, I would assume that the order of your includes like shown above should be ok, because the only script with an autoexecute section is included first. If you would include the hotkeys first, I would understand that the other one wouldn't work.)

Re: #Include scripts breaks

Posted: 19 Jan 2018, 14:52
by micnolmad
gregster wrote:Just add the code of your two small hotkey scripts (2 and 3 above) to the end of AHK_HideMouseOnIdle.ahk . No need to #include them. That's what #include does, anyway.

(Without testing, I would assume that the order of your includes like shown above should be ok, because the only script with an autoexecute section is included first. If you would include the hotkeys first, I would understand that the other one wouldn't work.)
Thank you for taking your time to help but you didn't actually. Don't get me wrong I am not trying to be bitchy just stating that you didn't do anything I have asked help with. So if you can see why things break please tell me that.

~michael

Re: #Include scripts breaks

Posted: 19 Jan 2018, 15:34
by SirRFI
Please elaborate how do they "break".

I assume only the first loads in, and the others not. That's caused by first encountered return in the code. If You put nothing but return in first included file, and nothing but a MsgBox % "test" in second, the MsgBox won't appear, unless you revert include order.

Re: #Include scripts breaks

Posted: 19 Jan 2018, 21:03
by boiler
@SirRFI: But he didn't put code that is expected to be run just by executing the script, such as a simple MsgBox. They are hotkey definitions, and they are supposed to appear after the first return in the code.

Re: #Include scripts breaks

Posted: 19 Jan 2018, 23:59
by gregster
micnolmad wrote:Thank you for taking your time to help but you didn't actually. Don't get me wrong I am not trying to be bitchy just stating that you didn't do anything I have asked help with. So if you can see why things break please tell me that.

~michael
Well, I can only see what is there... there is nothing obvious wrong. But, we might not have the whole picture.
Have you tried it then to put these three scripts into one file - hotkeys at the end (it could help to find the problem)? What happened? Did it also break? What means "break" - error message or just doesn't (partially) work? For me, on Win10 64bit, the first script doesn't seem to work correctly either way... but it is included without problem with the other two scripts.
Try to add a msgbox to the first included script to see if it is executed/really included.
Are you sure that the file paths of the includes are all correct? Try full paths, if you are not sure.
Is

Code: Select all

#Include AutoHotKey\AHK_HideMouseOnIdle.ahk
#Include AutoHotKey\AHK_TurnScreenOff.ahk
#Include AutoHotKey\AHK_WindowsSystemKBSC.ahk
really your complete code, or are there some other lines, possibly a return in front of it?
Which AHK and Windows versions are you running?

Re: #Include scripts breaks

Posted: 20 Jan 2018, 16:28
by wolf_II
There is a line that never gets executed in the AHK_HideMouseOnIdle.ahk script. I guess it's crucial to run at least once, so move it up into the auto-execute section. (not tested)

Code: Select all

OnExit, ShowCursor  ; Ensure the cursor is made visible when the script exits.

Re: #Include scripts breaks

Posted: 21 Jan 2018, 02:11
by gregster
Very good point, wolfII, although not related to the 'includes'. Micnolmad, could that cause the "broken" behaviour that you are seeing? But, of course, that would also apply to the stand-alone version...

Re: #Include scripts breaks

Posted: 21 Jan 2018, 03:30
by Exaskryz
Does the OnExit routine actually do anything? Imagine how the script is exited without a hotkey dedicated to it. The user would be interacting to either open task manager and likely navigate it with mouse or right click the tray icon to exit. I expect a user is not going to be doing that within 250 ms. The OnExit routine could be run if the user kills the script with keyboard navigation. So this may be why the OP is reporting the code works just fine. But as we have concluded, the standalone and #Include behavior should be the same in regards to this "broken" script.