55using System . Linq ;
66using System . Runtime . InteropServices ;
77using System . Windows . Forms ;
8+ using System . Windows . Input ;
89using Microsoft . Vbe . Interop ;
910using Rubberduck . Common . Hotkeys ;
1011using Rubberduck . Common . WinAPI ;
1112using Rubberduck . Settings ;
1213using Rubberduck . UI . Command ;
14+ using Rubberduck . UI . Command . Refactorings ;
1315using NLog ;
16+ using Rubberduck . UI ;
1417
1518namespace Rubberduck . Common
1619{
1720 public class RubberduckHooks : IRubberduckHooks
1821 {
1922 private readonly VBE _vbe ;
2023 private readonly IntPtr _mainWindowHandle ;
24+ private readonly IntPtr _oldWndPointer ;
2125 private readonly User32 . WndProc _oldWndProc ;
26+ private User32 . WndProc _newWndProc ;
2227 private RawInput _rawinput ;
28+ private IRawDevice _kb ;
29+ private IRawDevice _mouse ;
2330 private readonly IGeneralConfigService _config ;
2431 private readonly IEnumerable < CommandBase > _commands ;
2532 private readonly IList < IAttachable > _hooks = new List < IAttachable > ( ) ;
@@ -30,8 +37,9 @@ public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<Comman
3037 _vbe = vbe ;
3138 _mainWindowHandle = ( IntPtr ) vbe . MainWindow . HWnd ;
3239 _oldWndProc = WindowProc ;
33- var oldWndPointer = User32 . SetWindowLong ( _mainWindowHandle , ( int ) WindowLongFlags . GWL_WNDPROC , WindowProc ) ;
34- _oldWndProc = ( User32 . WndProc ) Marshal . GetDelegateForFunctionPointer ( oldWndPointer , typeof ( User32 . WndProc ) ) ;
40+ _newWndProc = WindowProc ;
41+ _oldWndPointer = User32 . SetWindowLong ( _mainWindowHandle , ( int ) WindowLongFlags . GWL_WNDPROC , _newWndProc ) ;
42+ _oldWndProc = ( User32 . WndProc ) Marshal . GetDelegateForFunctionPointer ( _oldWndPointer , typeof ( User32 . WndProc ) ) ;
3543
3644 _commands = commands ;
3745 _config = config ;
@@ -55,10 +63,12 @@ public void HookHotkeys()
5563 var kb = ( RawKeyboard ) _rawinput . CreateKeyboard ( ) ;
5664 _rawinput . AddDevice ( kb ) ;
5765 kb . RawKeyInputReceived += Keyboard_RawKeyboardInputReceived ;
66+ _kb = kb ;
5867
5968 var mouse = ( RawMouse ) _rawinput . CreateMouse ( ) ;
6069 _rawinput . AddDevice ( mouse ) ;
6170 mouse . RawMouseInputReceived += Mouse_RawMouseInputReceived ;
71+ _mouse = mouse ;
6272
6373 foreach ( var hotkey in settings . Settings . Where ( hotkey => hotkey . IsEnabled ) )
6474 {
@@ -165,7 +175,7 @@ public void Detach()
165175 private void hook_MessageReceived ( object sender , HookEventArgs e )
166176 {
167177 var hotkey = sender as IHotkey ;
168- if ( hotkey != null && hotkey . Command . CanExecute ( null ) )
178+ if ( hotkey != null )
169179 {
170180 hotkey . Command . Execute ( null ) ;
171181 return ;
0 commit comments