Windows mobile Windows Mobile-禁用电源按钮

Windows mobile Windows Mobile-禁用电源按钮,windows-mobile,windows-mobile-5.0,Windows Mobile,Windows Mobile 5.0,是否有人成功捕获WM5设备上的电源/待机按钮,从而使您的代码阻止用户“关闭”屏幕 我有一个横向使用屏幕的应用程序,我想将电源键按下,这样(a)用户可以用双手握住设备,而不会意外关闭屏幕电源,并且(作为奖励-b)将其用作UI按钮 也许有人有低级黑客?我正在使用iPaq RX1950上交付的WM5 记住,没有不可能的事——特别是WM5。如果我同时自己回答,我会更新这个问题 更新! 我发现了三个与可用性相反的技巧: 补丁keybddr.dll(在此设备上),通过您喜欢的方式重新注入ROM。在这个带有

是否有人成功捕获WM5设备上的电源/待机按钮,从而使您的代码阻止用户“关闭”屏幕

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

也许有人有低级黑客?我正在使用iPaq RX1950上交付的WM5

记住,没有不可能的事——特别是WM5。如果我同时自己回答,我会更新这个问题


更新! 我发现了三个与可用性相反的技巧:

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

  • 同步到电源管理消息队列,并在设备出现故障时“打开”设备

  • 更改注册表中的“电源状态”,使其全部(大部分)“打开”。这样,我可以使用RAPI禁用电源按钮,并让设备上的软件在事件x、y和z上“重置”注册表


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

    另一种选择涉及多种因素的组合

    • 在无人参与模式下运行应用程序
    • 监视电源更改事件
    • 当设备更改为无人值守模式时,请求完全开启模式
    关于电源管理的全面讨论超出了我在这里所能讨论的范围。您可以在此处阅读更多信息:

    还有一个示例显示了如何在此处注册电源事件:

    以下代码不会禁用电源按钮,但如果设备关闭,它将在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
        }
    }
    
    使用系统;
    使用System.Runtime.InteropServices;
    使用System.Collections.Generic;
    使用系统文本;
    名称空间Core.Mobile
    {
    /// 
    ///允许操作电源管理,即系统待机
    /// 
    公共静态类操纵
    {
    #区域私有变量
    私有静态System.Threading.Timer _Timer=null;
    private const int INTERVAL=10000;//10秒
    #端区
    #区域公共方法
    /// 
    ///防止应用程序挂起/休眠
    /// 
    公共静态无效禁用睡眠()
    {
    如果(_timer==null)
    {
    _timer=new System.Threading.timer(new System.Threading.TimerCallback(timer_Tick),null,0,INTERVAL);
    }
    尝试
    {
    PowerPolicyNotify(PPN_UNATTENDEDMODE,1);//确保应用程序仍在挂起模式下运行
    }
    捕获{}
    }
    /// 
    ///允许挂起/休眠操作
    /// 
    公共静态void EnableSleep()
    {
    如果(_timer!=null)
    {
    _timer.Dispose();
    _定时器=空;
    }
    尝试
    {
    PowerPolicyNotify(PPN_无人参与模式,0);
    }
    捕获{}
    }
    #端区
    #区域私有方法
    /// 
    ///防止待机的内部定时器
    /// 
    私有静态无效计时器(对象状态)
    {
    尝试
    {
    SystemIdleTimeReset();
    设置系统状态(空、电源状态打开、电源强制);
    }
    捕获{}
    }
    #端区
    #平沃克区
    private const int PPN_UNATTENDEDMODE=0x00000003;
    电源状态的专用常数=0x00010000;
    私用电量/状态/关闭=0x00020000;
    私用常数int POWER\u STATE\u SUSPEND=0x00200000;
    私家警力=4096;
    专用常量int POWER\u STATE\u RESET=0x00800000;
    /// 
    ///此功能重置系统计时器,该计时器控制
    ///设备将自动进入暂停状态。
    /// 
    [DllImport(“CoreDll.dll”)]
    私有静态外部无效SystemIdleTimerReset();
    /// 
    ///此功能重置系统计时器,该计时器控制
    ///设备将自动进入暂停状态。
    /// 
    [DllImport(“CoreDll.dll”)]
    私有静态外部void SHIdleTimerReset();
    /// 
    ///此功能允许操作当前电源状态,即打开设备
    /// 
    [DllImport(“coredll.dll”,SetLastError=true)]
    静态外部int SETSYSTATE(字符串psState、int StateFlags、int选项);
    /// 
    ///此函数用于设置任何电源通知选项
    /// 
    [DllImport(“CoreDll.dll”)]
    静态外部boolpowerPolicyNotify(intdwmessage,intonoroff);
    #端区
    }
    }
    
    不过,这严重违反了最小意外的原则。不要。我也非常同意勒多菲尔的观点,把电源按钮作为一个额外的按钮是一个非常糟糕的主意。您正在使整个设备上最关键的按钮过载,更糟糕的是,您正在禁用它唯一的功能。首先,这是一个坏主意,通常是直接中断零。除非电源驱动程序有一个钩子(我知道没有WinMo设备有),否则就没有办法拦截它。客户机想要它,所以客户机得到它。;-)我必须同意Ben的观点-这是客户端设备(或我的设备)-这只是一个bu