Пример #1
0
        private void BeginBind(Hotkey.KeyAction action)
        {
            _hotkey = new Hotkey();
            _hotkey.Action = action;
            _hotkey.WinKey = Key.Escape;

            KeyDown += Window_KeyDown;
        }
Пример #2
0
        private static IntPtr KeyHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == WM_HOTKEY)
            {
                int _id = wParam.ToInt32();

                Hotkey _hotkey = RegisteredKeys.FirstOrDefault(k => k.Index == _id);

                if (_hotkey != null && _sidebar != null && _sidebar.Ready)
                {
                    switch (_hotkey.Action)
                    {
                    case KeyAction.Toggle:
                        if (_sidebar.Visibility == Visibility.Visible)
                        {
                            _sidebar.AppBarHide();
                        }
                        else
                        {
                            _sidebar.AppBarShow();
                        }
                        break;

                    case KeyAction.Show:
                        _sidebar.AppBarShow();
                        break;

                    case KeyAction.Hide:
                        _sidebar.AppBarHide();
                        break;

                    case KeyAction.Reload:
                        _sidebar.Reload();
                        break;

                    case KeyAction.Close:
                        App.Current.Shutdown();
                        break;

                    case KeyAction.CycleEdge:
                        if (_sidebar.Visibility == Visibility.Visible)
                        {
                            switch (Framework.Settings.Instance.DockEdge)
                            {
                            case DockEdge.Right:
                                Framework.Settings.Instance.DockEdge = DockEdge.Left;
                                break;

                            default:
                            case DockEdge.Left:
                                Framework.Settings.Instance.DockEdge = DockEdge.Right;
                                break;
                            }

                            Framework.Settings.Instance.Save();

                            _sidebar.Reposition();
                        }
                        break;

                    case KeyAction.CycleScreen:
                        if (_sidebar.Visibility == Visibility.Visible)
                        {
                            Monitor[] _monitors = Monitor.GetMonitors();

                            if (Framework.Settings.Instance.ScreenIndex < (_monitors.Length - 1))
                            {
                                Framework.Settings.Instance.ScreenIndex++;
                            }
                            else
                            {
                                Framework.Settings.Instance.ScreenIndex = 0;
                            }

                            Framework.Settings.Instance.Save();

                            _sidebar.Reposition();
                        }
                        break;

                    case KeyAction.ReserveSpace:
                        Framework.Settings.Instance.UseAppBar = !Framework.Settings.Instance.UseAppBar;
                        Framework.Settings.Instance.Save();

                        _sidebar.Reposition();
                        break;
                    }

                    handled = true;
                }
            }

            return(IntPtr.Zero);
        }
Пример #3
0
 private static void Unregister(Hotkey hotkey)
 {
     NativeMethods.UnregisterHotKey(
         new WindowInteropHelper(_window).Handle,
         hotkey.Index
         );
 }
Пример #4
0
        private static void Register(Hotkey hotkey)
        {
            uint _mods = MODIFIERS.MOD_NOREPEAT;

            if (hotkey.AltMod)
            {
                _mods |= MODIFIERS.MOD_ALT;
            }

            if (hotkey.CtrlMod)
            {
                _mods |= MODIFIERS.MOD_CONTROL;
            }

            if (hotkey.ShiftMod)
            {
                _mods |= MODIFIERS.MOD_SHIFT;
            }

            if (hotkey.WinMod)
            {
                _mods |= MODIFIERS.MOD_WIN;
            }

            NativeMethods.RegisterHotKey(
                new WindowInteropHelper(_window).Handle,
                hotkey.Index,
                _mods,
                hotkey.VirtualKey
                );
        }
Пример #5
0
        public static void Initialize(Sidebar window, Hotkey[] settings)
        {
            if (settings == null)
            {
                return;
            }

            Disable();

            _window = window;
            _index = 0;

            RegisteredKeys = settings.Select(h =>
            {
                h.Index = _index;
                _index++;
                return h;
            }).ToArray();

            (PresentationSource.FromVisual(window) as HwndSource).AddHook(KeyHook);
        }
Пример #6
0
        public static void Initialize(Sidebar window, Hotkey[] settings)
        {
            if (settings == null || settings.Length == 0)
            {
                Dispose();
                return;
            }

            Disable();

            _sidebar = window;
            _index = 0;

            RegisteredKeys = settings.Select(h =>
            {
                h.Index = _index;
                _index++;
                return h;
            }).ToArray();

            window.HwndSource.AddHook(KeyHook);

            IsHooked = true;
        }