autohotkey

Alternative for Connected To Internet(), it doesn‘t work


This command is just invalid, it doesn‘t work.

Code:

Internet = disconnected


Internet:
If Connected To Internet()
{
Internet = connected
}
else {
Sound beep 1000,250
Internet = disconnected
}
return

<^<!=::Msg Box internet:%internet%

What can I use instead of the Connected to Internet () function??

Any answer? Thanks.

Also, I‘m using the 1.1.37 version of AutoHotKey.

Edit:- I just did not know such a “magical function” never existed from the start. Sorry if I seemed too rude or dumb. Don't take this question as a recommendation either; it was posted in the AHK_L days.

And yeah, I know: The question was not started correctly, no context was given, the code was structured incorrectly, half of it was following OTB and half of it wasn't, the string definitions were incorrect, yada yada… I was just a bad coder AND asker back in the days, sorry. However, do take the answer as a suggestion as for what is to be done in this case.


Solution

  • Try

    <^<!=::
        If DllCall("Wininet.dll\InternetGetConnectedState", "Str", 0x40,"Int",0) 
            MsgBox, 262208, Info, Internet = connected
        else
        {
            SoundBeep 1000,250
            MsgBox,4144, Warning, Internet = disconnected
        }
    return