Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trigger on 'laptop goes to battery power'
#1
From email:
Quote:Please let me know whether it is possible to get a trigger when the
Power Icon in the system tray appears as a battery symbol (or changes
to a battery symbol in case the power icon is always there), with the
partial text: *remaning* (if you hover the mouse over it).

Run this function. To run automatically at startup, assign 'QM file loaded' trigger.

Function PowerEvents
Code:
Copy      Help
function# hWnd message wParam lParam
if(hWnd) goto messages
if(getopt(nthreads)>1) ret

MainWindow 0 "QM_Power" &PowerEvents 0 0 0 0 WS_POPUP

ret
;messages
int-- AC
SYSTEM_POWER_STATUS p
sel message
,case WM_CREATE
,GetSystemPowerStatus &p
,AC=p.ACLineStatus
,
,case WM_POWERBROADCAST
,sel wParam
,,case PBT_APMPOWERSTATUSCHANGE
,,GetSystemPowerStatus &p
,,if(p.ACLineStatus!=AC)
,,,AC=p.ACLineStatus
,,,
,,,out iif(AC "AC" "battery")
,,,
,,,;To run a macro when battery mode begins or ends, use mac here. Example:
,,,;mac "BatteryMode" "" !AC ;;first argument will be 1 if battery mode began, 0 if ended.
,,,
,,;This code also is executed on other power events.
,,;And you can find more info in other p members.
,,;Read more in MSDN Library, about PBT_APMPOWERSTATUSCHANGE and SYSTEM_POWER_STATUS.
,,
,,;This function runs all the time. To end it, use Threads dialog.
,,;You'll have to end it to apply changes after editing it.
,,
,case WM_DESTROY
,PostQuitMessage 0

ret DefWindowProc(hWnd message wParam lParam)


Forum Jump:


Users browsing this thread: 1 Guest(s)