Beispiel #1
0
        private void HookKey(Keys key, uint shift)
        {
            if (IsAttached)
            {
                return;
            }

            var hookId  = (IntPtr)Kernel32.GlobalAddAtom(Guid.NewGuid().ToString());
            var success = User32.RegisterHotKey(_hWndVbe, hookId, shift, (uint)key);

            if (!success)
            {
                Logger.Debug(RubberduckUI.CommonHotkey_KeyNotRegistered, key);
            }

            HotkeyInfo = new HotkeyInfo(hookId, Combo);
            IsAttached = true;
        }
Beispiel #2
0
        private void HookKey(Keys key, uint shift)
        {
            if (IsAttached)
            {
                return;
            }

            var hookId  = (IntPtr)Kernel32.GlobalAddAtom(Guid.NewGuid().ToString());
            var success = User32.RegisterHotKey(_hWndVbe, hookId, shift, (uint)key);

            if (!success)
            {
                Debug.WriteLine(Rubberduck.UI.RubberduckUI.CommonHotkey_KeyNotRegistered, key);
                //throw new Win32Exception(Rubberduck.UI.RubberduckUI.CommonHotkey_KeyNotRegistered, key);
            }

            HotkeyInfo = new HotkeyInfo(hookId, Combo);
            IsAttached = true;
            Debug.WriteLine("Hotkey '{0}' hooked successfully to command '{1}'", Key, Command.GetType());  //no translation needed for Debug.Writeline
        }
Beispiel #3
0
        public void Detach()
        {
            if (!IsAttached)
            {
                return;
            }

            if (!User32.UnregisterHotKey(_hWndVbe, HotkeyInfo.HookId))
            {
                Logger.Warn($"Error calling UnregisterHotKey on hokey with id {HotkeyInfo.HookId} for command of type {Command.GetType()}; the error was {Marshal.GetLastWin32Error()}; going to delete the atom anyway... The memory may leak.");
            }
            Kernel32.SetLastError(Kernel32.ERROR_SUCCESS);
            Kernel32.GlobalDeleteAtom(HotkeyInfo.HookId);
            var lastError = Marshal.GetLastWin32Error();

            if (lastError != Kernel32.ERROR_SUCCESS)
            {
                Logger.Warn($"Error calling DeleteGlobalAtom; the error was {lastError}, the id {HotkeyInfo.HookId} and the type of the associated command {Command.GetType()}.");
            }

            HotkeyInfo = new HotkeyInfo(IntPtr.Zero, Combo);
            ClearCommandShortcutText();
        }
Beispiel #4
0
        private void HookKey(Keys key, uint shift)
        {
            if (IsAttached)
            {
                return;
            }

            var hookId = (IntPtr)Kernel32.GlobalAddAtom(Guid.NewGuid().ToString());
            var success = User32.RegisterHotKey(_hWndVbe, hookId, shift, (uint)key);
            if (!success)
            {
                Debug.WriteLine(Rubberduck.UI.RubberduckUI.CommonHotkey_KeyNotRegistered, key);
                //throw new Win32Exception(Rubberduck.UI.RubberduckUI.CommonHotkey_KeyNotRegistered, key);
            }

            HotkeyInfo = new HotkeyInfo(hookId, Combo);
            IsAttached = true;
            Debug.WriteLine("Hotkey '{0}' hooked successfully to command '{1}'", Key, Command.GetType());  //no translation needed for Debug.Writeline
        }