@@ -77,9 +77,18 @@ static void Main(string[] args)
7777 TrayApplicationContext < ViewMain > trayApplicationContext = new TrayApplicationContext < ViewMain > ( ) ;
7878 MainForm = ( ViewMain ) trayApplicationContext . MainForm ;
7979
80- // Careful. Does bad things if the event handlers block the driver.
81- // TODO: Make Interceptor driver use toggle-able in the GUI
82- LoadInterceptorDriver ( ) ;
80+ // TODO: Make Interceptor driver use a GUI toggle
81+ bool useInterceptor = ( args . Length >= 2 && args [ 1 ] . ToLower ( ) . Equals ( "useinterceptor" ) ) ;
82+ InterceptorDriverInput = new Input ( ) ;
83+ if ( useInterceptor )
84+ {
85+ LOGGER . Info ( "Loading interceptor driver..." ) ;
86+ LoadInterceptorDriver ( ) ;
87+ if ( Tube . InterceptorDriverInput . IsLoaded )
88+ {
89+ LOGGER . Info ( "Interceptor driver loaded and will be used instead of SendInput() and hooks" ) ;
90+ }
91+ }
8392
8493 // Native keyboard and mouse hook initialization
8594 KeyInterceptor . Initialize ( KeyboardHandler . HookCallback ) ;
@@ -99,17 +108,26 @@ static void Main(string[] args)
99108
100109 ProcessFileArg ( fileName ) ;
101110
102- LOGGER . Debug ( "Entering Application.Run()... " ) ;
111+ LOGGER . Debug ( "Entering Application.Run()" ) ;
103112 Application . Run ( trayApplicationContext ) ;
104- LOGGER . Debug ( "...returned from Application.Run()." ) ;
113+ LOGGER . Debug ( "Returned from Application.Run()." ) ;
105114 }
106115 finally
107116 {
117+ LOGGER . Info ( "Starting application exit cleanup..." ) ;
118+
108119 // Native class de-initialization
109120 MouseInterceptor . Unhook ( ) ;
110121 KeyInterceptor . Cleanup ( ) ;
111122 CmdFileReader . Dispose ( ) ;
112123 UnloadInterceptorDriver ( ) ;
124+
125+ LOGGER . Info ( "... end application exit cleanup" ) ;
126+
127+ if ( LOGGER . IsDebugEnabled )
128+ {
129+ WinConsole . Free ( ) ;
130+ }
113131 }
114132
115133 if ( WriteOnExit )
@@ -122,36 +140,29 @@ static void Main(string[] args)
122140
123141 private static void LoadInterceptorDriver ( )
124142 {
125- InterceptorDriverInput = new Input
143+ try
126144 {
127- KeyboardFilterMode = KeyboardFilterMode . All ,
128-
129145 // For mouse lock
130- MouseFilterMode = MouseFilterMode . MouseMove
131- } ;
146+ InterceptorDriverInput . MouseFilterMode = MouseFilterMode . MouseMove ;
132147
133- // Probably not needed unless we need the filter driver for both input and output
134- // IntercepterDriverWrapper.OnKeyPressed += IntercepterDriverWrapper_OnKeyPressed ;
148+ // Clicking in debug console with this enabled may lock all inputs and require reboot!
149+ InterceptorDriverInput . OnMousePressed += IntercepterDriverWrapper_OnMousePressed ;
135150
136- // Clicking in console with this enabled is very bad.
137- InterceptorDriverInput . OnMousePressed += IntercepterDriverWrapper_OnMousePressed ;
138-
139- try
140- {
141151 InterceptorDriverInput . Load ( ) ;
142152 }
143153 catch ( DllNotFoundException notFoundException )
144154 {
145- LOGGER . Info ( "Unable to load keyboard filter driver DLL. Make sure DLL is in application directory: " + notFoundException ) ;
155+ LOGGER . Warn ( "Unable to load keyboard filter driver DLL. Make sure DLL is in application directory: " + notFoundException ) ;
146156 return ;
147157 }
148158 catch ( Exception e )
149159 {
160+ // Code that simulates input should always check filter driver state
161+ // if Tube.InterceptorDriverInput.IsLoaded use it, otherwise use
162+ // SendInput
150163 LOGGER . Warn ( "Failed to load keyboard filter driver. SendInput will be used: " + e ) ;
151164 return ;
152165 }
153-
154- LOGGER . Info ( "Keyboard filter driver loaded and will be used instead of SendInput()!" ) ;
155166 }
156167
157168 private static void UnloadInterceptorDriver ( )
0 commit comments