Windows Mobile - Deshabilitar botón de encendido
-
03-07-2019 - |
Pregunta
¿Alguien ha atrapado con éxito el botón de encendido / en espera en un dispositivo WM5 de modo que su código impidió que los usuarios se apagaran? incluso la pantalla?
Tengo una aplicación que usa la pantalla en orientación horizontal y me gustaría atrapar la tecla de encendido para que (a) los usuarios puedan sostener el dispositivo con ambas manos y no apagar accidentalmente la pantalla y (como un bono - b) úsalo como un botón de interfaz de usuario.
¿Quizás alguien tiene un hack de bajo nivel? Estoy usando WM5 como se entrega en iPaq RX1950 (s).
Recuerde, no hay imposibles , especialmente con WM5. Mientras tanto, yo mismo respondo, actualizaré la pregunta.
¡Actualización!
Descubrí tres trucos que funcionan, en orden inverso de usabilidad:
-
Parche keybddr.dll (en este dispositivo), reinyecte en la ROM a través de sus medios favoritos. En este dispositivo con esta ROM de fábrica, funciona, pero no quería deshabilitarlo permanentemente.
-
Sincronice con la cola de mensajes de Power Management y encienda el dispositivo " cada vez que dice que está bajando.
-
Cambiar los "Estados de potencia" en el registro para que estén todos (la mayoría de ellos) " en " ;. De esta manera, puedo usar RAPI para deshabilitar el botón de encendido y tener el software en el dispositivo "restablecer" el registro en el evento x, y y z.
Solución
La implementación del botón de encendido depende del OEM, por lo que no es probable que una solución en un dispositivo funcione en otro dispositivo. Debido a la amplia variedad de implementaciones en dispositivos Windows Mobile, encontrará que esto es cierto con muchas características de bajo nivel.
La alternativa implica una combinación de cosas
- Ejecute su aplicación en modo desatendido
- Monitorear los eventos de cambio de poder
- cuando el dispositivo cambia a modo desatendido solicitud completa en modo
Una discusión completa sobre la administración de energía está más allá de lo que puedo discutir aquí. Puedes leer más sobre esto aquí: http://www.codeproject.com/KB/mobile/WiMoPower1.aspx
También hay una muestra que muestra cómo uno puede registrarse para eventos de energía aquí: http://www.codeproject.com/KB/mobile/WiMoQueue.aspx
Otros consejos
El siguiente código no deshabilitará el botón de encendido, pero si el dispositivo se apaga, volverá a encenderlo en 10 segundos. También deshabilitará cualquier funcionalidad de ahorro de energía.
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;
namespace Core.Mobile
{
/// <summary>
/// Allows manipulation the power management i.e. system standby
/// </summary>
public static class PowerManipulation
{
#region Private variables
private static System.Threading.Timer _timer = null;
private const int INTERVAL = 10000; //10 seconds
#endregion
#region Public methods
/// <summary>
/// Prevents the application from suspending/sleeping
/// </summary>
public static void DisableSleep()
{
if (_timer == null)
{
_timer = new System.Threading.Timer(new System.Threading.TimerCallback(Timer_Tick), null, 0, INTERVAL);
}
try
{
PowerPolicyNotify(PPN_UNATTENDEDMODE, 1); //Ensure the application still runs in suspend mode
}
catch { }
}
/// <summary>
/// Allows suspend/sleep operations
/// </summary>
public static void EnableSleep()
{
if (_timer != null)
{
_timer.Dispose();
_timer = null;
}
try
{
PowerPolicyNotify(PPN_UNATTENDEDMODE, 0);
}
catch { }
}
#endregion
#region Private methods
/// <summary>
/// Internal timer for preventing standby
/// </summary>
private static void Timer_Tick(object state)
{
try
{
SystemIdleTimerReset();
SetSystemPowerState(null, POWER_STATE_ON, POWER_FORCE);
}
catch { }
}
#endregion
#region PInvoke
private const int PPN_UNATTENDEDMODE = 0x00000003;
private const int POWER_STATE_ON = 0x00010000;
private const int POWER_STATE_OFF = 0x00020000;
private const int POWER_STATE_SUSPEND = 0x00200000;
private const int POWER_FORCE = 4096;
private const int POWER_STATE_RESET = 0x00800000;
/// <summary>
/// This function resets a system timer that controls whether or not the
/// device will automatically go into a suspended state.
/// </summary>
[DllImport("CoreDll.dll")]
private static extern void SystemIdleTimerReset();
/// <summary>
/// This function resets a system timer that controls whether or not the
/// device will automatically go into a suspended state.
/// </summary>
[DllImport("CoreDll.dll")]
private static extern void SHIdleTimerReset();
/// <summary>
/// This function allows the current power state to be manipulated, i.e. turn the device on
/// </summary>
[DllImport("coredll.dll", SetLastError = true)]
static extern int SetSystemPowerState(string psState, int StateFlags, int Options);
/// <summary>
/// This function sets any power notification options
/// </summary>
[DllImport("CoreDll.dll")]
static extern bool PowerPolicyNotify(int dwMessage, int onOrOff);
#endregion
}
}