コード例 #1
0
ファイル: HotkeyHelper.cs プロジェクト: hawkwork/CasualMeter
 public void Unregister(ModifierKeys modKey, Key key)
 {
     var hotkey = new HotKey(key, modKey);
     if (_actions.ContainsKey(hotkey))
     {
         _manager.Unregister(hotkey);
         _actions.Remove(hotkey);
     }
 }
コード例 #2
0
ファイル: HotKeyManager.cs プロジェクト: kirmir/GlobalHotKey
        /// <summary>
        /// Registers the system-wide hot key.
        /// </summary>
        /// <param name="hotKey">The hot key.</param>
        public void Register(HotKey hotKey)
        {
            // Check if specified hot key is already registered.
            if (_registered.ContainsKey(hotKey))
                throw new ArgumentException("The specified hot key is already registered.");

            // Register new hot key.
            var id = getFreeKeyId();
            if (!WinApi.RegisterHotKey(_windowHandleSource.Handle, id, hotKey.Key, hotKey.Modifiers))
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Can't register the hot key.");

            _registered.Add(hotKey, id);
        }
コード例 #3
0
 public MCommand(HotKey h, string _descriptiveName, string _keyName)
 {
     _hotkey = h;
     descriptiveName = _descriptiveName;
     keyName = _keyName;
     hotKeyText = h.ToString();
     try
     {
         commands.Add(_keyName, this);
     }
     catch (ArgumentException)
     {
         throw new InvalidOperationException("MCommand key name already added.");
     }
 }
コード例 #4
0
 public static bool IsCallbackExists( HotKeyCallBackHandler cb, out HotKey hotkey)
 {
     if (cb == null) throw new ArgumentNullException(nameof(cb));
     try
     {
         var key = _keymap.First(x => x.Value == cb).Key;
         hotkey = key;
         return true;
     }
     catch (InvalidOperationException)
     {
         // not found
         hotkey = null;
         return false;
     }
 }
コード例 #5
0
ファイル: HotkeyHelper.cs プロジェクト: hawkwork/CasualMeter
        public void Register(ModifierKeys modKey, Key key, Action action)
        {
            try
            {
                var hotkey = new HotKey(key, modKey);
                if (_actions.ContainsKey(hotkey))
                    throw new ArgumentException("Hotkey already registered!");
                _actions[hotkey] = action;

                _manager.Register(hotkey);
            }
            catch (Exception e)
            {
                Logger.Warn($"Failed to register the hotkey {modKey}+{key}. {e.Message}");
            }
        }
コード例 #6
0
ファイル: HotKeyManager.cs プロジェクト: stufkan/SimpleAudio
        public void AddHotKey(Key key, ModifierKeys modifiers, Action action)
        {
            if (key == Key.None)
                throw new ArgumentException("A key was not specified for this hotkey.", "key");
            if (modifiers == ModifierKeys.None)
                throw new ArgumentException("A modifier was not specified for this hotkey.", "modifiers");
            if (action == null)
                throw new ArgumentNullException("An action is required when adding a HotKey.", "action");

            HotKey hk = hotkeys.Values.Where(x => x.Key == key && x.Modifiers == modifiers).FirstOrDefault();
            if (hk == null)
            {
                int id = idgen.Next();
                hk = new HotKey(id, key, modifiers);
                hotkeys.Add(id, hk);
                RegisterHotKey(id, key, modifiers);
            }
            hk.AddAction(action);
        }
コード例 #7
0
 private void unregisterHotkey()
 {
     try
     {
         if (_hk != null)
         {
             _hk.Dispose();
             _hk = null;
         }
     }
     catch (Exception)
     {
     }
 }
コード例 #8
0
ファイル: Config.cs プロジェクト: TingPing/elpis
 public HotkeyConfig(HotKey h)
 {
     Command = h.Command;
     Key = h.Key;
     Modifiers = h.Modifiers;
     Global = h.Global;
     Enabled = h.Enabled;
 }
コード例 #9
0
ファイル: HotkeyHelper.cs プロジェクト: lunyx/CasualMeter
        private void Register(ModifierKeys modKey, Key key, Action action)
        {
            try
            {
                var hotkey = new HotKey(key, modKey);
                if (_actions.ContainsKey(hotkey))
                    return;
                _actions[hotkey] = action;

                _manager.Register(hotkey);
            }
            catch (Exception e)
            {
                Logger.Warn($"Failed to register the hotkey {modKey}+{key}. {e.Message}");
            }
        }
コード例 #10
0
        private void registerHotkey()
        {
            try
            {
                unregisterHotkey();

                if (Settings.Default.UseHotKey)
                {
                    Keys hotkey;
                    if (Settings.Default.HotKey == 0)
                    {
                        hotkey = Keys.Home;
                    }
                    else
                    {
                        hotkey = (Keys)KeyInterop.VirtualKeyFromKey((Key)Settings.Default.HotKey);
                    }

                    _hk = new HotKey(ModifierKeys.Windows | ModifierKeys.Alt, hotkey, this);
                    _hk.HotKeyPressed += k =>
                    {
                        this.Activate();
                    };
                }
            }
            catch (Exception)
            {
            }
        }
コード例 #11
0
 public static bool IsHotkeyExists( HotKey hotKey )
 {
     if (hotKey == null) throw new ArgumentNullException(nameof(hotKey));
     return _keymap.Any( v => v.Key.Equals( hotKey ) );
 }
コード例 #12
0
 public static bool Regist( HotKey key, HotKeyCallBackHandler callBack )
 {
     if (key == null)
         throw new ArgumentNullException(nameof(key));
     if (callBack == null)
         throw new ArgumentNullException(nameof(callBack));
     try
     {
         _hotKeyManager.Register(key);
         _keymap[key] = callBack;
         return true;
     }
     catch (ArgumentException)
     {
         // already called this method with the specific hotkey
         // return success silently
         return true;
     }
     catch (Win32Exception)
     {
         // this hotkey already registered by other programs
         // notify user to change key
         return false;
     }
 }
コード例 #13
0
 public static string HotKey2Str( HotKey key )
 {
     if (key == null) throw new ArgumentNullException(nameof(key));
     return HotKey2Str( key.Key, key.Modifiers );
 }
コード例 #14
0
		private void OnHotKeyHandler_WatchProc(HotKey hotKey)
		{
			if (Properties.Settings.Default.playVoice)
			{
				if (WatchProc)
				{
					SoundPlayer sp = new SoundPlayer(Properties.Resources.stop2);
					sp.Play();
				}
				else
				{
					SoundPlayer sp = new SoundPlayer(Properties.Resources.start2);
					sp.Play();

				}
			}
			WatchProc = !WatchProc;
		}
コード例 #15
0
ファイル: HotKeyManager.cs プロジェクト: kirmir/GlobalHotKey
 /// <summary>
 /// Unregisters previously registered hot key.
 /// </summary>
 /// <param name="hotKey">The registered hot key.</param>
 public void Unregister(HotKey hotKey)
 {
     int id;
     if (_registered.TryGetValue(hotKey, out id))
     {
         WinApi.UnregisterHotKey(_windowHandleSource.Handle, id);
         _registered.Remove(hotKey);
     }
 }
コード例 #16
0
 public static void UnRegist(HotKey key)
 {
     if (key == null)
         throw new ArgumentNullException(nameof(key));
     _hotKeyManager.Unregister(key);
     if(_keymap.ContainsKey(key))
         _keymap.Remove(key);
 }
コード例 #17
0
ファイル: HotKeyManager.cs プロジェクト: kirmir/GlobalHotKey
        private IntPtr messagesHandler(IntPtr handle, int message, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (message == WinApi.WmHotKey)
            {
                // Extract key and modifiers from the message.
                var key = KeyInterop.KeyFromVirtualKey(((int)lParam >> 16) & 0xFFFF);
                var modifiers = (ModifierKeys)((int)lParam & 0xFFFF);

                var hotKey = new HotKey(key, modifiers);
                onKeyPressed(new KeyPressedEventArgs(hotKey));

                handled = true;
                return new IntPtr(1);
            }

            return IntPtr.Zero;
        }
コード例 #18
0
		public MainWindow()
		{

			if (Settings.Default.UpgradeRequired)
			{
				Settings.Default.Upgrade();
				Settings.Default.UpgradeRequired = false;
				Settings.Default.Save();
			}
		

			InitializeComponent();
			tbico.DoubleClickCommand = new ShowAppCommand(this);
			tbico.DataContext = this;

			if (Settings.Default.Do_minimize)
			{
				this.Hide();
				Settings.Default.Do_minimize = false;
				Settings.Default.Save();
			}


			db = new DBManager(Utility.userDBPath);
			Utility.im = new InformationManager(Utility.infoDBPath);

			items = new ObservableCollection<GameExecutionInfo>();
			db.LoadGame(items);

			GameListView.ItemsSource = items;
			GameListView.SelectedItem = null;
			UpdateStatus();
			OnPropertyChanged("ItemCount");

			_hotkey = new HotKey(Key.F9, KeyModifier.Alt, OnHotKeyHandler_WatchProc);
			_hotkey = new HotKey(Key.F8, KeyModifier.Alt, OnHotKeyHandler_ErogeHelper);

			RegisterInStartup(Properties.Settings.Default.setStartUp);

			watchProcTimer = new System.Windows.Threading.DispatcherTimer();
			watchProcTimer.Tick += new EventHandler(dispatcherTimer_Tick);
			watchProcTimer.Interval = new TimeSpan(0, 0, Properties.Settings.Default.monitorInterval);
			watchProcTimer.Start();

			if (Settings.Default.checkUpdate)
			{
				Thread t = new Thread(doCheckUpdate);
				t.Start();
			}

		}
コード例 #19
0
		private void OnHotKeyHandler_ErogeHelper(HotKey hotKey)
		{
			ErogeHelper = !ErogeHelper;
		}
コード例 #20
0
 public void register_hotkey()
 {
     HotKeyHost hotKeyHost = new HotKeyHost((HwndSource)HwndSource.FromVisual(this));
     HotKey hotkey = new HotKey(Key.P, ModifierKeys.Shift|ModifierKeys.Control, true);
     hotkey.HotKeyPressed += new EventHandler<HotKeyEventArgs>(delegate(Object o, HotKeyEventArgs e)
     {
         AppController.Current.open_compose_window();
     });
     hotKeyHost.AddHotKey(hotkey);
 }
コード例 #21
0
ファイル: HotKeyManager.cs プロジェクト: kirmir/GlobalHotKey
 /// <summary>
 /// Unregisters previously registered hot key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="modifiers">The key modifiers.</param>
 public void Unregister(Key key, ModifierKeys modifiers)
 {
     var hotKey = new HotKey(key, modifiers);
     Unregister(hotKey);
 }
コード例 #22
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // To prevent App.MainWindow being set to DisplayInputWindow,
            // Set "new MainWindow()" manually at first.
            MainWindow = new MainWindow();

            // 01. Single Instance only allowed.

            mMutex = new Mutex(true, APP_SIGNATURE, out mMutexCreatedNew);
            if (!mMutexCreatedNew)
            {
                MessageBox.Show("二重起動しました。アプリケーションを終了します。",
                    APP_SIGNATURE, MessageBoxButton.OK, MessageBoxImage.Error);
                App.Current.Shutdown();
            }

            // 02. Load SoundPacks

            try
            {
                SoundPacks = SoundPacks.Load(ConfigDir);

                foreach (var s in SoundPacks)
                {
                    if (!Directory.Exists(s.Location))
                        throw new DirectoryNotFoundException(s.Location);
                }
            }
            catch
            {
                SoundPacks = new SoundPacks();

                try
                {
                    var sounds_dir = Path.Combine(GetStartupPath(), "Sounds");
                    foreach (var d in new DirectoryInfo(sounds_dir).GetDirectories())
                        SoundPacks.Add(new SoundPack(d.FullName));
                }
                catch
                {
                    MessageBox.Show("初期化エラー。再インストールが必要です。アプリケーションは終了します");
                    App.Current.Shutdown();
                }
            }

            // 03. Load SoundEngine

            try
            {
                SoundEngine = SoundEngine.Load(ConfigDir);
            }
            catch
            {
                SoundEngine = SoundEngine.FromSoundPack(SoundPacks[0]);
            }

            SoundEngine.PropertyChanged += (_sender, _e) =>
            {
                switch (_e.PropertyName)
                {
                    case "Location":
                        ShowBaloonTip("サウンドパック {0} をロードしました",
                            SoundEngine.Name);
                        break;
                    case "MuteEnabled":
                        ShowBaloonTip("ミュートを {0} にしました",
                            SoundEngine.MuteEnabled ? "有効" : "無効");
                        break;
                    case "DefaultSoundEnabled":
                        ShowBaloonTip("デフォルトサウンドを {0} にしました",
                            SoundEngine.MuteEnabled ? "有効" : "無効");
                        break;
                    case "PressedKeys":
                        DisplayInput.Keys = SoundEngine.PressedKeys;
                        break;
                }
            };

            // 04. Load DisplayInputWindow

            try
            {
                DisplayInput.Load(ConfigDir);
            }
            catch /* Load Default Value */
            {
                DisplayInput.DisplayMargin = 25;
                DisplayInput.DisplayPosition = DisplayInputWindow.Position.TopRight;
                DisplayInput.Visible = true;
            }

            // 05. Prepare NotifyIcon

            mNotifyIcon.Text = APP_SIGNATURE;
            mNotifyIcon.ContextMenuStrip = mContextMenuStrip;
            mNotifyIcon.Visible = true;
            mNotifyIcon.Icon = new Icon(
                Path.Combine(GetStartupPath(), "SoundKeyboard.ico"),
                new System.Drawing.Size(16, 16)
            );
            mNotifyIcon.DoubleClick += new EventHandler(ToggleMainWindowVisible);
            mContextMenuStrip.Opening += new CancelEventHandler(ContextMenuStrip_Opening);

            ContextMenuStrip_Opening(); // Call once to initialize mContextMenuStrip.

            // 06. Register Hotkeys

            mHotKeyMute = new HotKey(
                Key.X, KeyModifier.Win,
                (_) => { SoundEngine.MuteEnabled = !SoundEngine.MuteEnabled; }
            );

            mHotKeyDisplayInput = new HotKey(
                Key.K, KeyModifier.Win,
                (_) => { DisplayInput.Visible = !DisplayInput.Visible; }
            );

            App.ShowBaloonTip("起動しました");
        }
コード例 #23
0
ファイル: HotKeyManager.cs プロジェクト: kirmir/GlobalHotKey
 /// <summary>
 /// Registers the system-wide hot key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="modifiers">The key modifiers.</param>
 /// <returns>The registered <see cref="HotKey"/>.</returns>
 public HotKey Register(Key key, ModifierKeys modifiers)
 {
     var hotKey = new HotKey(key, modifiers);
     Register(hotKey);
     return hotKey;
 }