Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Alert when power/network cable is plugged off


  • Please log in to reply
59 replies to this topic
Z_Gecko
  • Guests
  • Last active:
  • Joined: --
or: http://www.autohotke...topic39033.html

Maria-
  • Members
  • 17 posts
  • Last active: Jul 22 2009 09:05 PM
  • Joined: 29 May 2009
Thanks for your attempt. That A_Ping thing gives me error and da other one is not working ;(

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
What error exactly do you get with A_Ping() ? I think you have not read the first post carefully: it requires the COM library to be present in the AutoHotkey\lib folder. See the bottom of the NetCon Alert script; uncomment the last #include line once you placed COM.ahk in the lib folder.

Also, for the speech anouncement you must have a working TTS engine installed. It works with SAPI4 in Win9x and SAPI5 in Win9x and later.

Does the compiled exe in the archive work at all for you? What is your operating system?

Maria-
  • Members
  • 17 posts
  • Last active: Jul 22 2009 09:05 PM
  • Joined: 29 May 2009
Complied .exe file works fine for me with voice alert. but source files aint working. when I run A_ping.ahk, it gives me this error:
Error: parameter #1 invalid.
Specifically: integerFast
Line#
..
...
This program will exit.

netcon alert.ahk also shows this error with additional another error ;(

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Please make sure you have latest AutoHotkey version installed. The IntegerFast and FloatFast parameters have been introduced with 1.0.48.x.

Also please make sure the function is being called correctly; the example should be pretty straightforward in this regard.

Maria-
  • Members
  • 17 posts
  • Last active: Jul 22 2009 09:05 PM
  • Joined: 29 May 2009
hey mate, thanks a lottt. after upgrading to the latest version, its working fine :D can you help me a bit more abt power status issue? i jus need a simple sound alert [ like da one u set for network cable] only when power cable is unplugged.

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Unfortunately I do not have access to a laptop to test such script but it shouldn't be hard to patch into the speech routine of the NetCon Alert script. You'll have to rely on someone else's help on this matter though. Sorry. :(

Maria-
  • Members
  • 17 posts
  • Last active: Jul 22 2009 09:05 PM
  • Joined: 29 May 2009
Hiyaaa
i m kinda stuck wid dis part of da program. can anyone edit it so dat it alerts only when power cable is unplugged , right now its giving alert always witch current battery status ;(
#Persistent
DetectHiddenWindows, on
MainID := WinExist("Ahk_PID " . DllCall("GetCurrentProcessId"))
OnMessage(0x218, "WM_POWERBROADCAST")
return
WM_POWERBROADCAST(wparam, lparam, msg, hwnd)
{
   Local sps
   If (hwnd != MainID)
      return
   VarSetCapacity(sps, 12, 0)
   DllCall("GetSystemPowerStatus", "UInt", &sps)
   ACLineStatus := NumGet(sps, 0, "char")
   BatteryFlag := NumGet(sps, 1, "char")
   BatteryLifePercent := NumGet(sps, 2, "char")
   BatteryLifeTime := NumGet(sps, 4, "int")
   BatteryFullLifeTime := NumGet(sps, 8, "int")
   SetTimer, ShowMsgBox, -10
}

ShowMsgBox:
powersource := ACLineStatus ? "AC power" : "battery power"
batterystate := BatteryFlag & 8 ? "charging" : (ACLineStatus ? "fully charged" : "draining")
msgbox,
( ltrim
   The computer is currently powered by %powersource%.
   The Battery is now at %BatteryLifePercent%`% and is %batterystate%.
)
return


Z_Gecko
  • Guests
  • Last active:
  • Joined: --
say, did you try to write at least one line of code yourself?

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Here, try this (untested):
#Persistent
DetectHiddenWindows, on
MainID := WinExist("Ahk_PID " . DllCall("GetCurrentProcessId"))
OnMessage(0x218, "WM_POWERBROADCAST")
return
WM_POWERBROADCAST(wparam, lparam, msg, hwnd)
{
   Local sps
   If (hwnd != MainID)
      return
   VarSetCapacity(sps, 12, 0)
   DllCall("GetSystemPowerStatus", "UInt", &sps)
   ACLineStatus := NumGet(sps, 0, "char")
   if !ACLineStatus
     SetTimer, ShowMsgBox, -10
}

ShowMsgBox:
msgbox, 0x1030, Warning!, The power cable has been unplugged!
return

Of course, the code could be shortened a bit by losing the ACLineStatus variable:

[...]
   DllCall("GetSystemPowerStatus", "UInt", &sps)
   if !NumGet(sps, 0, "char")
     SetTimer, ShowMsgBox, -10
[...]


Maria-
  • Members
  • 17 posts
  • Last active: Jul 22 2009 09:05 PM
  • Joined: 29 May 2009
wow, just amazing, thanks a lot Drugwash, u have done it!!!! :D now my mission is to combine them both to make a single .exe file :roll:

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
My friendly advice would be for you to try your best to understand what all this is about. The way the whole world works, you're likely to stumble into this stuff sooner or later and it's best you learn something about it all.

Good luck anyways! ;)

Maria-
  • Members
  • 17 posts
  • Last active: Jul 22 2009 09:05 PM
  • Joined: 29 May 2009
trying :cry: ;'(

purloinedheart
  • Members
  • 538 posts
  • Last active: Sep 22 2014 09:35 PM
  • Joined: 04 Apr 2008
Hope your teacher doesn't ask for a fully commented script :roll:

Maria-
  • Members
  • 17 posts
  • Last active: Jul 22 2009 09:05 PM
  • Joined: 29 May 2009
errm.... dont scare me nemore ;@@ i m already enuff stressed abt dis ;( jus wana get over it anyhow