I already found this on the internet but I don't know how to modyfy it to the shortcut, probably quite simple .
Code: Select all
; 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
}
#SingleInstance force
#NoTrayIcon
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, 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