Windows Mobile - 禁用电源按钮

时间:2009-04-29 10:57:11

标签: windows-mobile windows-mobile-5.0

是否有人成功地将电源/待机按钮锁定在WM5设备上,以致您的代码阻止用户“关闭”甚至屏幕?

我有一个横向使用屏幕的应用程序,我想要按下电源按键,以便(a)用户可以用双手握住设备而不会意外关闭屏幕(如奖金 - b)将其用作UI按钮。

也许某人有低级别的黑客攻击?我在iPaq RX1950上使用WM5。

请记住,没有不可能的事情 - 特别是对于WM5。如果我在此期间自己回答,我会更新问题。


更新!

我发现了三种可行的技巧,与可用性的顺序相反:

  1. Patch keybddr.dll(在此设备上),通过您最喜欢的方式重新注入ROM。在这个带有这个工厂ROM的设备上 - 它可以工作,但我不想永久禁用它。

  2. 同步到电源管理消息队列,并在设备显示正在关闭时将其打开。

  3. 更改注册表中的“电源状态”,以便它们(大部分)都“打开”。这样,我就可以使用RAPI来禁用电源按钮,让设备上的软件“重置”事件x,y和z上的注册表。

2 个答案:

答案 0 :(得分:3)

电源按钮的实现取决于OEM,因此一台设备上的解决方案不太可能在另一台设备上运行。由于Windows Mobile设备的实现差异很大,您会发现许多低级功能都是如此。

替代方案涉及事物的组合

  • 以无人参与模式运行您的应用程序
  • 监控电源变更事件
  • 当设备更改为无人参与模式请求已满模式

关于电源管理的完整讨论超出了我在此讨论的内容。你可以在这里读更多关于它的内容: http://www.codeproject.com/KB/mobile/WiMoPower1.aspx

还有一个示例显示了如何注册电力事件: http://www.codeproject.com/KB/mobile/WiMoQueue.aspx

答案 1 :(得分:0)

以下代码不会禁用电源按钮,但如果设备关闭,它将在10秒内重新打开设备。它还将禁用任何省电功能。

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
    }
}