est
est

Reputation: 11855

Hook Windows Mobile 6.5 phone on/off button

recently this post inspired me, I want to track my own life, too.

I take a look at my cellphone's clock every time when go to sleep or after wake up, so I need some program to hook to my cellphone's on/off button, and log the timestamp when I press it.

I am using WM6.5 on a HTC TyTN II. If there is existing software that can do this with few settings and tweaks it would be nice, but I can also write code myself. Any suggestions?

Upvotes: 2

Views: 905

Answers (2)

ctacke
ctacke

Reputation: 67178

You can use the device power notifications by P/Invoking RequestPowerNotifications to know when a power state changes (there's a CodeProject article that covers this as well). Be aware that the power down notification doesn't wait for subscribers to run code, so in most cases your application's handler doesn't actually run until the device wakes back up (meaning that if you're writing a timestamp or something you're going to get the wake time, not the sleep time).

Also be aware that different devices handle power management differently, so YMMV.

Upvotes: 1

Jeremy O'Donoghue
Jeremy O'Donoghue

Reputation: 816

This is more tricky than you could possibly imagine!

The 'on/off' button isn't directly available to the OS (i.e. it's not visible in the keypad driver), as it is hooked into a rather complex system of power collapse (basically, the Apps CPU is completely powered down when the phone is 'off' - the modem wakes up according to the network-configured paging cycle).

The wake-sleep interactions of the two CPUs are extremely complex, and prone to race conditions. Even if you managed to hook it (which would require deep kernel-level programming and a number of security hacks), you would probably make your phone very unstable.

Upvotes: 1

Related Questions