Sign in to follow this  
Followers 0
beqa

battery beeper

17 posts in this topic

hello all.

i want to make a script which will play sounds when charger is connected or disconnected.

below is the code whic works only on script start

$bsound = _BatteryQueryEx()

Switch $bsound[0]
Case 0
SoundPlay(@WindowsDir & "mediatada.wav", 1)
Case 1
SoundPlay(@WindowsDir & "mediading.wav", 1)
EndSwitch
 

after that is udf code.

how i can to make it to monitor status and if charger wil disconnect it'll play a sound.

thanks

Share this post


Link to post
Share on other sites



You need to download the >UDF from the forum. ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

i have an udf i didn't paste the whole code.

scripts works but only if you run script, but aftr that connecting disconnecting cable doesn't give efect

Share this post


Link to post
Share on other sites

this is whole code.

$batt = _BatteryQueryEx()

Switch $batt[0]
Case 0
SoundPlay(@WindowsDir & "mediatada.wav", 1)
Case 1
SoundPlay(@WindowsDir & "mediading.wav", 1)
EndSwitch


#include-once
;======================================================
;    _BatteryQueryEx()
;    original author PsaltyDS <a href='#531988' class='bbc_url' title=''>http://www.autoitscript.com/forum/index.php?showtopic=10993&view=findpost&p=531988</a>
;    Rajesh V R - addition of BatteryFullLifeTime
;    Return information on the Battery
;    Sets @Error on error
;    Returns an array:
;        $array[0]    = ACPower(0=offline, 1=online, 255=unknown)
;        $array[1]    = BatteryFlag(1=High>66%, 2=Low<33%, 4=Critical<5%,
;                      8=Charging 128=No Battery, 255=Unknown
;                      Use BitAnd to test, ie BitAnd($array[1],128)
;        $array[2]    = BatteryLife %(0-100, 255=unknown)
;        $array[3]    = Seconds left of charge, estimate(4294967295=unknown)
;        $array[4]    = BatteryLife @ Full Capacity (Seconds of battery life if fully charged -1 if info not available Not applicable for AC Source)
;   @Link :         <a href='http://msdn.microsoft.com/en-us/library/aa373232(VS.85' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/aa373232(VS.85</a>).aspx
;======================================================
Func _BatteryQueryEx()
Local $SystemPower, $ret, $array[5]

; Setup $array and $SystemPower
$SystemPower = DllStructCreate("ubyte;ubyte;ubyte;ubyte;ulong;ulong")
If @error Then
SetError(-1)
Return $array
EndIf

; make the DllCall
$ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($SystemPower))
If @error Then;DllCall Failed
SetError(-2)
$SystemPower = 0
Return $array
EndIf

If Not $ret[0] Then; GetSystemPowerStatus Failed
SetError(-3)
$SystemPower = 0
Return $array
EndIf

; Fill the array
$array[0] = DllStructGetData($SystemPower, 1);    AC
$array[1] = DllStructGetData($SystemPower, 2);    Battery Charge
$array[2] = DllStructGetData($SystemPower, 3);    Battery Charge %
$array[3] = DllStructGetData($SystemPower, 5);    Sec Battery Left
$array[4] = DllStructGetData($SystemPower, 6);    Sec Battery Capacity @ Full Charge

; free the struct
$SystemPower = 0

Return $array
EndFunc;==>_BatteryQueryEx

Share this post


Link to post
Share on other sites

can you show a sample?

Share this post


Link to post
Share on other sites

While 1
Switch $batt[0]
Case 0
SoundPlay(@WindowsDir & "mediatada.wav", 1)
Case 1
SoundPlay(@WindowsDir & "mediading.wav", 1)
EndSwitch
sleep(10)
WEnd

 

is it right?

Share this post


Link to post
Share on other sites

and can't understand what is going

$batt = _BatteryQueryEx()
$state = $batt[0]

While 1
if $batt[0]=0 then
$state=0
elif batt[0]=1 then
$state=1
endif
sleep(10)
wend
Switch $state
Case 0
SoundPlay(@WindowsDir & "mediatada.wav", 1)
Case 1
SoundPlay(@WindowsDir & "mediading.wav", 1)
EndSwitch
 

Share this post


Link to post
Share on other sites

Try this.

$batt = _BatteryQueryEx()
$state = $batt[0]

While 1
    $batt = _BatteryQueryEx()
    If $batt[0] <> $state Then
        $state = $batt[0]
        Switch $state
            Case 0
                SoundPlay(@WindowsDir & "\media\tada.wav", 1)
            Case 1
                SoundPlay(@WindowsDir & "\media\ding.wav", 1)
        EndSwitch

    EndIf
    Sleep(10)
WEnd

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

thanks, it works.

sorry, missed var in the loop.

Share this post


Link to post
Share on other sites

for not drain cpu?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0