Disabling the power key in windows mobile device

  • Thread starter Thread starter Tammy Nejadian
  • Start date Start date
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
 
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.
 
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.
 
Back
Top