Disabling the power key in windows mobile device

T

Tammy Nejadian

Hi,
I am trying to disable the power key in windows mobile version 6.0 while my
application is running. The user should not be able to turn off or turn on
the device. Those functionalities should happen by programming using C#
codes. Could someone please help me with that? Is there any site that
explains how to disable the power key on PDA device using C# codes?

Thanks,
Tammy
 
P

Peter Morris

public static class Device
{
[DllImport("CoreDll.dll")]
public static extern void SystemIdleTimerReset();

private static int DisableSleepCallsCount = 0;
private static System.Threading.Timer PreventSleepTimer = null;


public static void EnableDeviceSleep()
{
DisableSleepCallsCount--;
if (DisableSleepCallsCount == 0)
{
if (PreventSleepTimer != null)
{
PreventSleepTimer.Dispose();
PreventSleepTimer = null;
}
}
}

public static void DisableDeviceSleep()
{
DisableSleepCallsCount++;
if (DisableSleepCallsCount == 1)
{
TimerCallback keepAlive = new System.Threading.TimerCallback(
delegate(object applicationData)
{
try
{
SystemIdleTimerReset();
}
catch (Exception)
{
}
}
);
PreventSleepTimer = new System.Threading.Timer(keepAlive, null, 0, 30 *
1000);
}
}
}

Not sure whether it disables the power key or not, but it stops it from
going into sleep mode. I used to use it when importing lots of data.
 
T

Tammy Nejadian

Thank you so much for the codes. I used the codes however still am able to
turn off/on the device by using powr button. I have to disable that button
some how. I even used the registry key to power off and on the device but
still I am able to intract with power button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top