Created
August 22, 2016 02:45
-
-
Save altbdoor/0372ff82882b7806873d25f863d4a9ed to your computer and use it in GitHub Desktop.
Simple AHK GUI to display current battery percentage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; https://autohotkey.com/board/topic/7022-acbattery-status/ | |
ReadInteger( p_address, p_offset, p_size, p_hex=true ) | |
{ | |
value = 0 | |
old_FormatInteger := a_FormatInteger | |
if ( p_hex ) | |
SetFormat, integer, hex | |
else | |
SetFormat, integer, dec | |
loop, %p_size% | |
value := value+( *( ( p_address+p_offset )+( a_Index-1 ) ) << ( 8* ( a_Index-1 ) ) ) | |
SetFormat, integer, %old_FormatInteger% | |
return, value | |
} | |
GetBatteryStatus() | |
{ | |
VarSetCapacity(powerStatus, 1+1+1+1+4+4) | |
success := DllCall("GetSystemPowerStatus", "UInt", &powerStatus) | |
acLineStatus:=ReadInteger(&powerstatus,0,1,false) | |
batteryFlag:=ReadInteger(&powerstatus,1,1,false) | |
batteryLifePercent:=ReadInteger(&powerstatus,2,1,false) | |
batteryLifeTime:=ReadInteger(&powerstatus,4,4,false) | |
batteryFullLifeTime:=ReadInteger(&powerstatus,8,4,false) | |
output := {} | |
output.acLineStatus := acLineStatus | |
output.batteryFlag := batteryFlag | |
output.batteryLifePercent := batteryLifePercent | |
output.batteryLifeTime := batteryLifeTime | |
output.batteryFullLifeTime := batteryFullLifeTime | |
Return output | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance force | |
#NoTrayIcon | |
#Include lib.ahk | |
GUI: | |
Temp := "--" | |
Gui, Font, s14 w700, Arial | |
Gui, Add, Text, w280 x10 y10 Center vGuiAcLineStatus, %Temp% | |
Gui, Font, s48 w700, Arial | |
Gui, Add, Text, w280 x10 y30 Center vGuiBatteryPercent, %Temp%`% | |
Gui, Font, s10 w400, Arial | |
Gui, Add, Button, Center w120 h30 x90 y105 gExecuteShutdown, Shutdown | |
Gui, Show, Center w300, AHK Battery Percent | |
Loop | |
{ | |
BatteryStatus := GetBatteryStatus() | |
If (BatteryStatus.acLineStatus == 0) | |
{ | |
Gui, Font, s14 w700 cRed, Arial | |
Temp := "Discharging" | |
} | |
Else | |
{ | |
Gui, Font, s14 w700 cGreen, Arial | |
Temp := "Charging" | |
} | |
GuiControl, Font, GuiAcLineStatus | |
GuiControl, , GuiAcLineStatus, %Temp% | |
Temp := BatteryStatus.batteryLifePercent | |
If (Temp == 255) | |
{ | |
Temp := "?" | |
} | |
Else | |
{ | |
Temp = %Temp%`% | |
} | |
GuiControl, , GuiBatteryPercent, %Temp% | |
Sleep, 1000 | |
} | |
Return | |
ExecuteShutdown: | |
MsgBox, 36, Shutdown Computer?, Are you sure you want to shutdown your computer now? | |
IfMsgBox No | |
{ | |
Return | |
} | |
Else | |
{ | |
Shutdown, 1 | |
} | |
GuiClose: | |
ExitApp | |
Return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment