注册热键

 

 

       //
        // 摘要:
        //     实现系统全局热键注册辅助类
        public class RegisterHotKeyHelper
        {
                public RegisterHotKeyHelper();

                //
                // 摘要:
                //     主窗体句柄
                public IntPtr WindowHandle { get; set; }
                //
                // 摘要:
                //     系统控制键
                public MODKEY ModKey { get; set; }
                //
                // 摘要:
                //     系统支持的键
                public Keys Keys { get; set; }
                //
                // 摘要:
                //     定义热键的参数,建议从10000开始
                public int WParam { get; set; }

                //
                // 摘要:
                //     热键处理事件
                public event HotKeyPass HotKey;

                //
                // 摘要:
                //     注册热键
                public static bool RegisterHotKey(IntPtr wnd, int id, MODKEY mode, Keys vk);
                //
                // 摘要:
                //     取消热键
                public static bool UnregisterHotKey(IntPtr wnd, int id);
                //
                // 摘要:
                //     开始注册系统全局热键
                public void StarHotKey();
                //
                // 摘要:
                //     取消系统全局热键
                public void StopHotKey();

                //
                // 摘要:
                //     控制键枚举
                public enum MODKEY
                {
                        //
                        // 摘要:
                        //     Alt控制键
                        MOD_ALT = 1,
                        //
                        // 摘要:
                        //     Ctrl控制键
                        MOD_CONTROL = 2,
                        //
                        // 摘要:
                        //     Shift控制键
                        MOD_SHIFT = 4,
                        //
                        // 摘要:
                        //     Windows键
                        MOD_WIN = 8
                }

                //
                // 摘要:
                //     热键处理代理定义
                public delegate void HotKeyPass();
        }

 

  

      private void SetHotKey()
        {
            try
            {
                hotKey2.Keys = Keys.S;
                hotKey2.ModKey = RegisterHotKeyHelper.MODKEY.MOD_ALT;
                hotKey2.WindowHandle = this.Handle;
                hotKey2.WParam = 10003;
                hotKey2.HotKey += new RegisterHotKeyHelper.HotKeyPass(hotKey2_HotKey);
                hotKey2.StarHotKey();
            }
            catch (Exception ex)
            {
                MessageDxUtil.ShowError(ex.Message);
                LogTextHelper.WriteLine(ex.ToString());
            }
        }
    
    

void hotKey2_HotKey()
{
notifyMenu_Show_Click(null, null);
}

 
        public MainForm()
        {
            InitializeComponent();

            SplashScreen.Splasher.Status = "正在展示相关的内容...";
            System.Threading.Thread.Sleep(1000);
            Application.DoEvents();

            InitUserRelated();

            DevExpress.XtraBars.Helpers.SkinHelper.InitSkinGallery(rgbiSkins, true);
            this.ribbonControl.Toolbar.ItemLinks.Clear();
            this.ribbonControl.Toolbar.ItemLinks.Add(rgbiSkins);
            UserLookAndFeel.Default.SetSkinStyle("Office 2010 Blue");

            SplashScreen.Splasher.Status = "初始化完毕...";
            System.Threading.Thread.Sleep(100);
            Application.DoEvents();

            SplashScreen.Splasher.Close();
            SetHotKey();
        }

 

posted @ 2022-03-11 00:43  彭二狗的牵引绳  阅读(64)  评论(0)    收藏  举报