Maffe811 Posted August 2, 2011 Share Posted August 2, 2011 Here is the UDF, cause im not sure if this is the original: ; #FUNCTION# ======================================================================================================================== ; Function Name: _BatteryQuery ; Description: Return information on the Battery. ; Syntax _BatteryQuery ( ) ; Parameter(s): None. ; Return Value(s): Success: Returns 4 elements array: ; $array[0] - ACPower (0 - Offline, 1 - Online, 255 - Unknown) ; $array[1] - BatteryFlag (1 - High, 2 - Low, 4 - Critical, 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) ; ; Failure: Returns 0 and sets the @error flag to non-zero. ; Author(s): - ; Note(s): - ;==================================================================================================================================== func _BatteryQuery() local $tStruct = DllStructCreate('ubyte;ubyte;ubyte;ubyte;ulong;ulong') local $aRet, $aRes[4] $aRet = DllCall('kernel32.dll', 'int', 'GetSystemPowerStatus', 'ptr', DllStructGetPtr($tStruct)) if (@error) or ($aRet[0] = 0) then $aRet = 1 endif $aRes[0] = DllStructGetData($tStruct, 1) ; AC $aRes[1] = DllStructGetData($tStruct, 2) ; Battery Charge $aRes[2] = DllStructGetData($tStruct, 3) ; Battery Charge, % $aRes[3] = DllStructGetData($tStruct, 5) ; Battery Left, Sec $tStruct = 0 if $aRet = 1 then return SetError(1, 0, 0) endif return SetError(0, 0, $aRes) endfunc; _BatteryQuery Now... I don't understand how to use it! Ive tried diffentr things. If some one could point me in the right direction, i would be most gratefull. All I need to know is when the charger is connected and when its not. [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
BrewManNH Posted August 2, 2011 Share Posted August 2, 2011 Add this to the top of the script: #include <array.au3> Global $array = _BatteryQuery() _ArrayDisplay($array) Now run it on a laptop and look at the contents of $array in the _ArrayDisplay output. Look at the explanation in the header of the UDF for what the values mean. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
taietel Posted August 2, 2011 Share Posted August 2, 2011 Or this: $aQuery = _BatteryQuery() Switch $aQuery[0] Case 1;AC Power online ConsoleWrite("On AC Power") Case 0;AC Power offline ConsoleWrite("On battery") Case Else;AC Power unknown ConsoleWrite("On your own") EndSwitch Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
wakillon Posted August 2, 2011 Share Posted August 2, 2011 Now... I don't understand how to use it! That's because you don't know SetError function : $aRes[0] = DllStructGetData($tStruct, 1) ; AC $aRes[1] = DllStructGetData($tStruct, 2) ; Battery Charge $aRes[2] = DllStructGetData($tStruct, 3) ; Battery Charge, % $aRes[3] = DllStructGetData($tStruct, 5) ; Battery Left, Sec return SetError(0, 0, $aRes) ;==> SetError ( code [, extended [, return value]] ) So it return $aRes value, who is an array, as it is writed in your post : "; Return Value(s): Success: Returns 4 elements array" Look in my signature for a monitoring battery script. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Maffe811 Posted August 2, 2011 Author Share Posted August 2, 2011 Now, i understand why everything i did failed. Or this: $aQuery = _BatteryQuery() Switch $aQuery[0] Case 1;AC Power online ConsoleWrite("On AC Power") Case 0;AC Power offline ConsoleWrite("On battery") Case Else;AC Power unknown ConsoleWrite("On your own") EndSwitch As you ca see, Taietel is using $aQuery[0], I would be using $aQuery[1]. Thats why everything i did failed. Also the lack of sleep didnt help! Thank you for the help, i can now complete my program! [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now