Esempio n. 1
0
        // hot key
        // not complete
        public static void SetHotKey()
        {
            HotKeySet hks = new HotKeySet(new[] { Keys.T, Keys.LShiftKey, Keys.RShiftKey });

            hks.RegisterExclusiveOrKey(new[] { Keys.LShiftKey, Keys.RShiftKey });
            //if(is)
        }
Esempio n. 2
0
        /// <summary>
        /// 显示  注册界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MetroMenuItem_Click(object sender, RoutedEventArgs e)
        {
            //显示  设置窗体
            var win = HotKeySet.CreateInstance();

            if (!win.IsVisible)
            {
                win.ShowDialog();
            }
            else
            {
                win.Activate();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 初始化并注册快捷键
        /// </summary>
        /// <param name="listHotKeyModel">待注册的快捷键集合,初始为空,再次注册时则不为空</param>
        /// <returns>成功 true 并保存全局变量的值  失败 false 弹出重新注册的界面</returns>
        private bool InitHotKey(ObservableCollection <HotKeyModel> listHotKeyModel = null)
        {
            //参数为空,加载配置文件中的数据,否则,按照界面设置的数据进行设置
            var listHKM = listHotKeyModel ?? HotKeyInit.Instance.LoadJsonFileInfo();

            if (listHKM == null)
            {
                MessageBox.Show("加载配置文件失败");
                return(false);
            }

            string strFali = HotKeyManager.RegisterAllHotKey(listHKM, m_Hwnd, out m_HotKeyDic);

            //返回的字符串为空则全局注册成功
            if (string.IsNullOrEmpty(strFali))
            {
                //更新配置文件数据
                File.WriteAllText("HotKey.json", JsonConvert.SerializeObject(listHKM));
                return(true);
            }

            //注册失败,弹出选择框,是否重新注册快捷键
            MessageBoxResult mbResult = MessageBox.Show(string.Format("无法注册下列快捷键\n\r{0}是否重新注册?", strFali), "提示", MessageBoxButton.YesNo);

            if (mbResult == MessageBoxResult.Yes)
            {
                var win = HotKeySet.CreateInstance();

                if (!win.IsVisible)
                {
                    win.ShowDialog();
                }
                else
                {
                    win.Activate();
                }

                return(false);
            }

            return(false);
        }