Jump to content

Recommended Posts

Posted

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

Posted

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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

Posted

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

Posted

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?

Posted

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
 

  • Solution
Posted

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.

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
×
×
  • Create New...