public static int Main(string[] args) { if (SingleApplicationInstance.IsAlreadyRunning()) return 1; Application.SetCompatibleTextRenderingDefault(true); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException, true); Application.EnableVisualStyles(); using (_keyboardHook = new KeyboardHook()) { _capsHook = _keyboardHook.CreateKeyHook(Keys.CapsLock); _capsHook.SuppressInput = true; _capsHook.KeyDown += new KeyEventHandler(OnCapsKeyDown); _capsHook.KeyUp += new KeyEventHandler(OnCapsKeyUp); EnsureCapsLockDisabled(); var thisAssembly = Assembly.GetExecutingAssembly(); var assemblyCatalog = new AssemblyCatalog(thisAssembly); var coreCatalog = new AssemblyCatalog(typeof(ICommand).Assembly); var catalog = new AggregateCatalog(assemblyCatalog, coreCatalog); var container = new CompositionContainer(catalog); // Todo: Hack: Forcing creation of command factories. container.GetExportedValues<ICommandFactory>(); _commandProvider = container.GetExportedValue<ICommandProvider>(); NotificationForm.Show("Ephemeral"); Application.Run(); } EnsureCapsLockDisabled(); return 0; }
void ClearInputHooks() { _keyboardHook.Dispose(); _keyboardHook = null; _mouseHook.Dispose(); _mouseHook = null; }
void SetInputHooks() { _keyboardHook = new KeyboardHook(); _keyboardHook.KeyDown += e => { if (!e.IsRepeat) OnInput(); }; _mouseHook = new MouseHook(); _mouseHook.MouseMove += new MouseMoveEventHandler(delegate { OnInput(); }); _mouseHook.MouseClick += new MouseClickEventHandler(OnInput); }