Ejemplo n.º 1
0
        private void RegisterHotKey()
        {
            var lines = File.ReadAllLines(Directory.GetCurrentDirectory() + "\\hotkeys.txt");

            foreach (var line in lines)
            {
                var record = line.Split(' ');

                var key = (Keys)Enum.Parse(typeof(Keys), record[0]);

                if (record[1].Contains("PlayPool"))
                {
                    var hotkeyNoMod = new HotkeyButton(key);
                    var actionNoMod = (HotkeyAction)Enum.Parse(typeof(HotkeyAction), record[1]);

                    HotkeyMap.Add(hotkeyNoMod, actionNoMod);

                    var hotkeyModCtrl = new HotkeyButton(key, (int)ModKeys.ModCtrl);
                    var actionModCtrl = (HotkeyAction)Enum.Parse(typeof(HotkeyAction), record[1] + "ModCtrl");

                    HotkeyMap.Add(hotkeyModCtrl, actionModCtrl);

                    var hotkeyModAlt = new HotkeyButton(key, (int)ModKeys.ModAlt);
                    var actionModAlt = (HotkeyAction)Enum.Parse(typeof(HotkeyAction), record[1] + "ModAlt");

                    HotkeyMap.Add(hotkeyModAlt, actionModAlt);

                    var hotkeyModCtrlAlt = new HotkeyButton(key, (int)ModKeys.ModCtrl | (int)ModKeys.ModAlt);
                    var actionModCtrlAlt =
                        (HotkeyAction)Enum.Parse(typeof(HotkeyAction), record[1] + "ModCtrlAlt");

                    HotkeyMap.Add(hotkeyModCtrlAlt, actionModCtrlAlt);
                }
                else
                {
                    var hotkey = new HotkeyButton(key);
                    var action = (HotkeyAction)Enum.Parse(typeof(HotkeyAction), record[1]);

                    HotkeyMap.Add(hotkey, action);
                }
            }
        }
Ejemplo n.º 2
0
        private void OnKeyPressed(object sender, GlobalKeyboardHookEventArgs e)
        {
            const int ctrlKeyCode = 162;
            const int altKeyCode  = 164;

            var keyCode = e.KeyboardData.VirtualCode;

            if (keyCode == ctrlKeyCode || keyCode == altKeyCode)
            {
                if (
                    !ModKeyAltDown &&
                    keyCode == altKeyCode &&
                    (
                        e.KeyboardState == GlobalKeyboardHook.KeyboardState.SysKeyDown ||
                        e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyDown
                    )
                    )
                {
                    ModKeyAltDown = true;
                }

                if (
                    !ModKeyCtrlDown &&
                    keyCode == ctrlKeyCode &&
                    (
                        e.KeyboardState == GlobalKeyboardHook.KeyboardState.SysKeyDown ||
                        e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyDown
                    )
                    )
                {
                    ModKeyCtrlDown = true;
                }

                if (
                    ModKeyAltDown &&
                    keyCode == altKeyCode &&
                    (
                        e.KeyboardState == GlobalKeyboardHook.KeyboardState.SysKeyUp ||
                        e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyUp
                    )
                    )
                {
                    ModKeyAltDown = false;
                }

                if (
                    ModKeyCtrlDown &&
                    keyCode == ctrlKeyCode &&
                    (
                        e.KeyboardState == GlobalKeyboardHook.KeyboardState.SysKeyUp ||
                        e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyUp
                    )
                    )
                {
                    ModKeyCtrlDown = false;
                }
            }
            else
            {
                var tModCtrl = ModKeyCtrlDown ? ModKeys.ModCtrl : 0;
                var tModAlt  = ModKeyAltDown ? ModKeys.ModAlt : 0;
                var modKey   = tModCtrl | tModAlt;

                Debug.WriteLine(keyCode);
                var hotkey = new HotkeyButton((Keys)keyCode, (int)modKey);

                if (!HotkeyMap.ContainsKey(hotkey))
                {
                    return;
                }

                if (
                    e.KeyboardState == GlobalKeyboardHook.KeyboardState.SysKeyDown ||
                    e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyUp
                    )
                {
                    AudioPlayer.Instance.ProcessHotkey(HotkeyMap[hotkey]);
                }

                e.Handled = true;
            }
        }