Skip to content

Commit 897bf65

Browse files
authored
Merge pull request #2060 from Hosch250/hotkeys
Hotkeys
2 parents 5b9bfd5 + 8971151 commit 897bf65

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,25 @@ namespace Rubberduck.Common
1616
{
1717
public class RubberduckHooks : IRubberduckHooks
1818
{
19-
private readonly VBE _vbe;
2019
private readonly IntPtr _mainWindowHandle;
20+
private readonly IntPtr _oldWndPointer;
2121
private readonly User32.WndProc _oldWndProc;
22+
private User32.WndProc _newWndProc;
2223
private RawInput _rawinput;
24+
private IRawDevice _kb;
25+
private IRawDevice _mouse;
2326
private readonly IGeneralConfigService _config;
2427
private readonly IEnumerable<CommandBase> _commands;
2528
private readonly IList<IAttachable> _hooks = new List<IAttachable>();
2629
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2730

2831
public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<CommandBase> commands)
2932
{
30-
_vbe = vbe;
3133
_mainWindowHandle = (IntPtr)vbe.MainWindow.HWnd;
3234
_oldWndProc = WindowProc;
33-
var oldWndPointer = User32.SetWindowLong(_mainWindowHandle, (int)WindowLongFlags.GWL_WNDPROC, WindowProc);
34-
_oldWndProc = (User32.WndProc)Marshal.GetDelegateForFunctionPointer(oldWndPointer, typeof(User32.WndProc));
35+
_newWndProc = WindowProc;
36+
_oldWndPointer = User32.SetWindowLong(_mainWindowHandle, (int)WindowLongFlags.GWL_WNDPROC, _newWndProc);
37+
_oldWndProc = (User32.WndProc)Marshal.GetDelegateForFunctionPointer(_oldWndPointer, typeof(User32.WndProc));
3538

3639
_commands = commands;
3740
_config = config;
@@ -55,10 +58,12 @@ public void HookHotkeys()
5558
var kb = (RawKeyboard)_rawinput.CreateKeyboard();
5659
_rawinput.AddDevice(kb);
5760
kb.RawKeyInputReceived += Keyboard_RawKeyboardInputReceived;
61+
_kb = kb;
5862

5963
var mouse = (RawMouse)_rawinput.CreateMouse();
6064
_rawinput.AddDevice(mouse);
6165
mouse.RawMouseInputReceived += Mouse_RawMouseInputReceived;
66+
_mouse = mouse;
6267

6368
foreach (var hotkey in settings.Settings.Where(hotkey => hotkey.IsEnabled))
6469
{

0 commit comments

Comments
 (0)