예제 #1
0
 public static void ProcessMouseHotkeys()
 {
     CheckCurrentHotkey();
     foreach (var pair in Handlers)
     {
         var bind = CheckInternal(pair.Key, true);
         if (bind != null && bind.UsesMouse)
         {
             var handler = pair.Value;
             if (handler.condition())
             {
                 bool waspressed = CheckPressed(
                     bind,
                     ref _prev_kbstate,
                     ref _prev_mousestate);
                 if (waspressed)
                 {
                     continue;
                 }
                 _current_hotkey?.keyuphandler?.Invoke();
                 _current_hotkey = handler;
                 handler.keydownhandler();
                 break;
             }
         }
     }
 }
 public Hotkey(Keys key, Modifiers modifiers, HotkeyHandler handler)
 {
     Key = key;
     Modifiers = modifiers;
     Handler = handler;
     Id = GetHashCode();
 }
예제 #3
0
 public static void ProcessKeyboardHotkeys()
 {
     if (CheckCurrentHotkey())
     {
         var kb = CheckInternal(_current_hotkey.hotkey, true);
         if (!kb.UsesMouse && _current_hotkey.repeat)
         {
             _current_hotkey.keydownhandler();
         }
         return;
     }
     _current_hotkey = null;
     foreach (var pair in Handlers)
     {
         var bind = CheckInternal(pair.Key, false);
         if (bind != null)
         {
             var handler = pair.Value;
             if (handler.condition())
             {
                 bool waspressed = CheckPressed(
                     bind,
                     ref _prev_kbstate,
                     ref _prev_mousestate);
                 if (waspressed && !handler.repeat)
                 {
                     continue;
                 }
                 handler.keydownhandler();
                 _current_hotkey = handler;
                 break;
             }
         }
     }
 }
        /// <summary>
        /// Handle configuration changed
        /// - apply changes as needed
        /// - Send telemetry
        /// </summary>
        /// <param name="testconfig"></param>
        internal void HandleConfigurationChanged(IReadOnlyDictionary <string, object> changes)
        {
            HotkeyHandler?.Dispose();
            InitHotKeys();

            var configManager = ConfigurationManager.GetDefaultInstance();

            SelectAction.GetDefaultInstance().IntervalMouseSelector = configManager.AppConfig.MouseSelectionDelayMilliSeconds;
            this.Topmost = configManager.AppConfig.AlwaysOnTop;
            this.ctrlTestMode.ctrlTabStop.SetHotkeyText(configManager.AppConfig.HotKeyForRecord);

            HighlightAction.GetDefaultInstance().HighlighterMode = configManager.AppConfig.HighlighterMode;

            configManager.TestConfig = TestSetting.GenerateSuiteConfiguration(RuleSelection.SuiteConfigurationType.Default);

            InitSelectActionMode();

            HideConfigurationMode();

            if (changes != null && changes.ContainsKey(ConfigurationModel.keyFontSize))
            {
                SetFontSize();
            }

            UpdateMainWindowUI();
            this.btnConfig.Focus();
        }
예제 #5
0
 protected override void OnClosed(EventArgs e)
 {
     _source.RemoveHook(HotkeyHandler.HwndHook);
     _source = null;
     HotkeyHandler.UnregisterHotKey(this);
     base.OnClosed(e);
 }
예제 #6
0
 public Hotkey(Keys key, Modifiers modifiers, HotkeyHandler handler)
 {
     Key       = key;
     Modifiers = modifiers;
     Handler   = handler;
     Id        = GetHashCode();
 }
예제 #7
0
        public static bool Register(IntPtr hwnd, Modifier modifier, Keys key, HotkeyHandler callback)
        {
            bool b = RegisterHotKey(hwnd, ++_idCount, (uint)modifier, (uint)key);

            _callbacks.Add(_idCount, callback);
            return(b);
        }
예제 #8
0
파일: Game.cs 프로젝트: EttienneS/karthus
    private void Update()
    {
        OnFirstRun();

        if (MainMenuController.MainMenuActive)
        {
            return;
        }

        if (_lastAutoSave == null)
        {
            // make the first autosave actually happen 5 mins after the game starts not on the first call
            _lastAutoSave = DateTime.Now;
        }
        else if ((DateTime.Now - _lastAutoSave.Value).TotalSeconds > 600)
        {
            // autosave every two minutes
            _lastAutoSave = DateTime.Now;
            SaveManager.SaveGame();
        }

        HotkeyHandler.HandleHotkeys();

        DestroyItemsInCache();
    }
예제 #9
0
        public static void Unregister(IntPtr hwnd, HotkeyHandler callback)
        {
            var item = _callbacks.FirstOrDefault(cb => cb.Value == callback);

            if (!item.Equals(default(KeyValuePair <int, HotkeyHandler>)))
            {
                UnregisterHotKey(hwnd, item.Key);
                _callbacks.Remove(item.Key);
            }
        }
예제 #10
0
파일: Proxy.cs 프로젝트: abrn/exalt-root
    public void FireHotkeyPressed(int id)
    {
        HotkeyHandler hotkeyPressed = this.HotkeyPressed;

        if (hotkeyPressed == null)
        {
            return;
        }
        hotkeyPressed(id);
    }
예제 #11
0
        /// <summary>
        /// Registers the hotkey with the manager.
        /// </summary>
        /// <param name="alias"></param>
        /// <param name="keys"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        public static bool Register(string alias, List<Keys> keys, HotkeyHandler<System.EventArgs> handler)
        {
            // Ensure this hotkey doesn't exist..
            if (_hotkeys.Any(h => h.Alias == alias.ToLower()))
                return false;

            // Insert the new hotkey..
            _hotkeys.Add(new Hotkey(alias, keys, handler));
            return true;
        }
예제 #12
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            IntPtr handle = new WindowInteropHelper(this).Handle;

            _source = HwndSource.FromHwnd(handle);
            _source.AddHook(HotkeyHandler.HwndHook);

            HotkeyHandler.RegisterHotKey(this);
        }
예제 #13
0
 public static void ProcessKeyup()
 {
     if (_current_hotkey != null)
     {
         if (!Check(_current_hotkey.hotkey))
         {
             _current_hotkey.keyuphandler?.Invoke();
             _current_hotkey = null;
         }
     }
 }
예제 #14
0
        public Hotkey(KeyGesture keyGesture, string description, MyAction action, HotkeyGroup group, HotkeyHandler handler)
        {
            KeyGesture  = keyGesture;
            Description = description;
            Action      = action;
            Group       = group;
            Handler     = handler;

            int virtualKeyCode = KeyInterop.VirtualKeyFromKey(KeyGesture.Key);

            Id = virtualKeyCode + ((int)KeyGesture.Modifiers * 0x10000);
        }
예제 #15
0
        /// <summary>
        /// Registers the hotkey with the manager.
        /// </summary>
        /// <param name="alias"></param>
        /// <param name="keys"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        public static bool Register(string alias, List <Keys> keys, HotkeyHandler <System.EventArgs> handler)
        {
            // Ensure this hotkey doesn't exist..
            if (_hotkeys.Any(h => h.Alias == alias.ToLower()))
            {
                return(false);
            }

            // Insert the new hotkey..
            _hotkeys.Add(new Hotkey(alias, keys, handler));
            return(true);
        }
예제 #16
0
        public HotkeyHandle Map(Hotkey hotkey, HotkeyHandler action)
        {
            var mapping = new HotkeyMapping {
                Hotkey = hotkey,
                Action = action,
                Id = Interlocked.Increment(ref _idCounter)
            };

            _agent.AddMapping(mapping);

            return HotkeyHandle.Create(() => _agent.RemoveMappingByHotkey(hotkey));
        }
        public override void KeyReleased(KeyPayload payload)
        {
            if (settings.MicType == MicTypeEnum.PTT)
            {
                VMManager.Instance.SetParam(BuildDeviceName(), 1);

                if (!String.IsNullOrEmpty(settings.MuteHotkey))
                {
                    HotkeyHandler.RunHotkey(settings.MuteHotkey);
                }
            }
        }
        public override void KeyPressed(KeyPayload payload)
        {
            // Used for long press
            //keyPressStart = DateTime.Now;
            //keyPressed = true;

            List <int> eList = JsonFiles.LoadJSONList("EntryList");

            SelectedCars = JsonFiles.LoadJSONList("Selected");
            string hotkey = "Numpad";
            string value  = "";
            int    carNum = 0;

            if (eList != null && eList.Count > 0 && settings.CarPosition > 0 && settings.CarPosition <= eList.Count)
            {
                value = eList[settings.CarPosition - 1].ToString();
            }

            for (int i = 0; i < value.Length; i++)
            {
                HotkeyHandler.RunHotkey("{" + hotkey + value[i] + "}");
            }
            Int32.TryParse(value, out carNum);

            if (carNum > 0)
            {
                bool isSel = false;
                foreach (var l in SelectedCars)
                {
                    if (l == carNum)
                    {
                        isSel = true;
                        break;
                    }
                }

                HotkeyHandler.RunHotkey("{Multiply}");
                if (!isSel)
                {
                    HotkeyHandler.RunHotkey("{Add}");
                    SelectedCars.Add(carNum);
                }
                else
                {
                    HotkeyHandler.RunHotkey("{Subtract}");
                    SelectedCars.Remove(carNum);
                }
                JsonFiles.SaveJSONList("Selected", SelectedCars);
            }

            Logger.Instance.LogMessage(TracingLevel.INFO, "Key Pressed");
        }
예제 #19
0
        public static bool Invoke(KeyGesture keyGesture, HotkeyHandler handler)
        {
            foreach (var hk in HotkeyMap)
            {
                var kg = hk.Value.KeyGesture;
                if (kg.Key == keyGesture.Key && kg.Modifiers == keyGesture.Modifiers && handler == hk.Value.Handler)
                {
                    return(hk.Value.Invoke());
                }
            }

            return(false);
        }
예제 #20
0
        public override void KeyReleased(KeyPayload payload)
        {
            if (!String.IsNullOrEmpty(settings.KeyReleaseValue))
            {
                VMManager.Instance.SetParameters(settings.KeyReleaseValue);
            }
            MidiCommandHandler.HandleMidiParameters(settings.ReleaseMidi);

            if (!String.IsNullOrEmpty(settings.ReleaseHotkey))
            {
                HotkeyHandler.RunHotkey(settings.ReleaseHotkey);
            }
        }
예제 #21
0
        public HotkeySettings()
        {
            InitializeComponent();

            saveBuffer.Config   = HotkeyHandler.GetHotkey(Configuration.HotkeyType.SaveBuffer);
            startBuffer.Config  = HotkeyHandler.GetHotkey(Configuration.HotkeyType.StartBuffer);
            stopBuffer.Config   = HotkeyHandler.GetHotkey(Configuration.HotkeyType.StopBuffer);
            toggleBuffer.Config = HotkeyHandler.GetHotkey(Configuration.HotkeyType.ToggleBuffer);

            startRecording.Config  = HotkeyHandler.GetHotkey(Configuration.HotkeyType.StartRecording);
            stopRecording.Config   = HotkeyHandler.GetHotkey(Configuration.HotkeyType.StopRecording);
            toggleRecording.Config = HotkeyHandler.GetHotkey(Configuration.HotkeyType.ToggleRecording);
        }
예제 #22
0
        /// <inheritdoc />
        public void RegisterHotkey(Hotkey hotkey, HotkeyHandler handler)
        {
            var vk   = KeyInterop.VirtualKeyFromKey((Key)hotkey.Key);
            var mods = hotkey.Modifiers;
            var id   = (vk << 8) | mods;

            if (!NativeMethods.RegisterHotKey(_sponge.Handle, id, mods, vk))
            {
                Debug.WriteLine("Could not register a hotkey", GetType().Name);
                return;
            }

            _hotkeyHandlerDic.Add(id, handler);
        }
        public static KeyboardState RemoveHotkeys(this KeyboardState self)
        {
            List <Keys> keys = new List <Keys>();

            foreach (Keys key in self.GetPressedKeys())
            {
                if (!HotkeyHandler.IsHotkey(key))
                {
                    keys.Add(key);
                }
            }

            return(new KeyboardState(keys.ToArray()));
        }
        private void InitializeSettings()
        {
            string mode1Hotkey = HotkeyHandler.ParseKeystroke(settings.Mode1Hotkey);
            string mode2Hotkey = HotkeyHandler.ParseKeystroke(settings.Mode2Hotkey);

            // If the parsed hotkey is different than what the user inputed, overwrite the user input
            // because it's invalid
            if (mode1Hotkey != settings.Mode1Hotkey || mode2Hotkey != settings.Mode2Hotkey)
            {
                settings.Mode1Hotkey = mode1Hotkey;
                settings.Mode2Hotkey = mode2Hotkey;
                SaveSettings();
            }
        }
예제 #25
0
        private void InitializeSettings()
        {
            string keypressHotkey = HotkeyHandler.ParseKeystroke(settings.KeypressHotkey);
            string releaseHotkey  = HotkeyHandler.ParseKeystroke(settings.ReleaseHotkey);

            // If the parsed hotkey is different than what the user inputed, overwrite the user input
            // because it's invalid
            if (keypressHotkey != settings.KeypressHotkey || releaseHotkey != settings.ReleaseHotkey)
            {
                settings.KeypressHotkey = keypressHotkey;
                settings.ReleaseHotkey  = releaseHotkey;
                SaveSettings();
            }
        }
예제 #26
0
 /// <summary>
 /// Checks if the currently pressed hotkey is still 'pressed' after a
 /// state change.
 /// </summary>
 public static bool CheckCurrentHotkey()
 {
     if (_current_hotkey != null)
     {
         if (Check(_current_hotkey.hotkey) &&
             _current_hotkey.condition())
         {
             return(true);
         }
         _current_hotkey.keyuphandler?.Invoke();
         _current_hotkey = null;
     }
     return(false);
 }
        public void LongKeyPressed()
        {
            longKeyPressed = true;
            if (!String.IsNullOrEmpty(settings.LongPressValue))
            {
                VMManager.Instance.SetParameters(settings.LongPressValue);
            }
            MidiCommandHandler.HandleMidiParameters(settings.LongMidi);

            if (!String.IsNullOrEmpty(settings.LongHotkey))
            {
                HotkeyHandler.RunHotkey(settings.LongHotkey);
            }
        }
        public async override void KeyPressed(KeyPayload payload)
        {
            Logger.Instance.LogMessage(TracingLevel.INFO, $"{this.GetType()} KeyPressed");
            if (!VMManager.Instance.IsConnected)
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"Key pressed but VM is not connected!");
                await Connection.ShowAlert();

                return;
            }

            bool triggeredMute = false;

            switch (settings.MicType)
            {
            case MicTypeEnum.SingleMode:
                int value;
                if (Int32.TryParse(settings.SingleValue, out value))
                {
                    VMManager.Instance.SetParam(BuildDeviceName(), value);
                    triggeredMute = value != 0;
                }
                else
                {
                    await Connection.ShowAlert();
                }
                break;

            case MicTypeEnum.Toggle:
                bool isMuted = VMManager.Instance.GetParamBool(BuildDeviceName());
                VMManager.Instance.SetParam(BuildDeviceName(), isMuted ? 0 : 1);
                triggeredMute = !isMuted;
                break;

            case MicTypeEnum.PTT:
                VMManager.Instance.SetParam(BuildDeviceName(), 0);
                triggeredMute = false;
                break;
            }

            if (triggeredMute && !String.IsNullOrEmpty(settings.MuteHotkey))
            {
                HotkeyHandler.RunHotkey(settings.MuteHotkey);
            }
            else if (!triggeredMute && !String.IsNullOrEmpty(settings.UnmuteHotkey))
            {
                HotkeyHandler.RunHotkey(settings.UnmuteHotkey);
            }
        }
        public override void KeyReleased(KeyPayload payload)
        {
            keyPressed = false;
            tmrRunLongPress.Stop();

            if (!longKeyPressed && !String.IsNullOrEmpty(settings.SetValue))
            {
                VMManager.Instance.SetParameters(settings.SetValue);
                MidiCommandHandler.HandleMidiParameters(settings.KeypressMidi);
                if (!String.IsNullOrEmpty(settings.KeypressHotkey))
                {
                    HotkeyHandler.RunHotkey(settings.KeypressHotkey);
                }
            }
        }
        public void LongKeyPressed()
        {
            longKeyPressed = true;
            Logger.Instance.LogMessage(TracingLevel.INFO, $"Long keypress");
            if (!String.IsNullOrEmpty(settings.LongPressValue))
            {
                VMManager.Instance.SetParameters(settings.LongPressValue);
            }
            MidiCommandHandler.HandleMidiParameters(settings.LongMidi);

            if (!String.IsNullOrEmpty(settings.LongHotkey))
            {
                HotkeyHandler.RunHotkey(settings.LongHotkey);
            }
        }
        public override void KeyReleased(KeyPayload payload)
        {
            tmrRunLongPress.Stop();

            if (!longKeyPressed && !String.IsNullOrEmpty(settings.SetValue))
            {
                Logger.Instance.LogMessage(TracingLevel.INFO, $"Short keypress");
                VMManager.Instance.SetParameters(settings.SetValue);
                MidiCommandHandler.HandleMidiParameters(settings.KeypressMidi);
                if (!String.IsNullOrEmpty(settings.KeypressHotkey))
                {
                    HotkeyHandler.RunHotkey(settings.KeypressHotkey);
                }
            }
        }
예제 #32
0
        private void HandleHotkey(KeyEventArgs e, HotkeyHandler handler)
        {
            if (e.IsRepeat)
            {
                return;
            }

            try
            {
                KeyGesture gesture = new KeyGesture(e.Key, Keyboard.Modifiers);
                e.Handled = Hotkey.Invoke(gesture, handler);
            }
            catch (Exception ex)
            {
                LogManager.Instance.Error(this, ex.ToString());
            }
        }
예제 #33
0
        private void HotKeyHandler_Tick(object sender, EventArgs e)
        {
            var now = DateTime.Now;

            //we can be super responsive when someone is tapping +- while not accidentally moving it up or down twice by doing manual checks while having the timer at ~5-10ms
            if (_lastHotkey == null)
            {
                _lastHotkey = now;
            }
            else if ((now - _lastHotkey).TotalMilliseconds < 100)
            {
                return;
            }

            var modifier    = (Keys)0;
            var fogModifier = (Keys)0;
            var up          = (Keys)0;
            var toggleFog   = (Keys)0;
            var down        = (Keys)0;

            TryParseKeys(settings.HotKeyModifier, ref modifier);
            TryParseKeys(settings.HotKeyFogModifier, ref fogModifier);
            TryParseKeys(settings.HotKeyUp, ref up);
            TryParseKeys(settings.HotKeyFog, ref toggleFog);
            TryParseKeys(settings.HotKeyDown, ref down);

            if (HotkeyHandler.IsKeyPushedDown(modifier))
            {
                if (HotkeyHandler.IsKeyPushedDown(up))
                {
                    SetFoVNumeric(FoVNumeric.Value + 1);
                    _lastHotkey = now;
                }
                if (HotkeyHandler.IsKeyPushedDown(down))
                {
                    SetFoVNumeric(FoVNumeric.Value - 1);
                    _lastHotkey = now;
                }
            }
            if (HotkeyHandler.IsKeyPushedDown(fogModifier) && HotkeyHandler.IsKeyPushedDown(toggleFog))
            {
                FogCheckBox.Checked = !FogCheckBox.Checked;
                _lastHotkey         = now;
            }
        }
예제 #34
0
파일: Hotkey.cs 프로젝트: 999eagle/Detox
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="alias"></param>
 /// <param name="keys"></param>
 /// <param name="handler"></param>
 public Hotkey(string alias, List<Keys> keys, HotkeyHandler<System.EventArgs> handler)
 {
     this.Alias = alias;
     this.Keys = keys;
     this.Handler = handler;
 }
예제 #35
0
        public void RegisterHotkey(Keys hotkey)
        {
            if (this._hotkeyHandler != null)
            {
                this.UnregisterHotkey();
            }

            if (hotkey == Keys.None)
            {
                return;
            }

            this._hotkeyHandler = new HotkeyHandler(this.Handle, hotkey);
            this._hotkeyHandler.Pressed += HotkeyPressed_Handler;
            try
            {
                this._hotkeyHandler.Register();
                System.Diagnostics.Debug.WriteLine("Registered shortcut for " + this.Title);
            }
            catch (Exception)
            {
                System.Diagnostics.Debug.WriteLine("Failed to register shortcut for " + this.Title);
                // There can be a lot of possible exception reasons here
                // In case of any of them the hotkey setting is silently ignored
            }
        }
예제 #36
0
        public void UnregisterHotkey()
        {
            if (this._hotkeyHandler == null)
            {
                return;
            }

            this._hotkeyHandler.Unregister();
            this._hotkeyHandler.Pressed -= HotkeyPressed_Handler;
            this._hotkeyHandler.Dispose();
            this._hotkeyHandler = null;
        }