public void ThrowsExceptionWhenInitializedTwice() { _runMutex.WaitOne(); using (var hooker = new KeystrokeHooker()) { Should.Throw <Exception>(() => new KeystrokeHooker()); } _runMutex.ReleaseMutex(); }
public void CanRegisterCallback() { _runMutex.WaitOne(); using (var hooker = new KeystrokeHooker()) { hooker.Callback += key => { }; } _runMutex.ReleaseMutex(); }
public void CanCreateTwoInSerial() { _runMutex.WaitOne(); using (var hooker = new KeystrokeHooker()) { hooker.Callback += key => { }; } using (var hooker = new KeystrokeHooker()) { hooker.Callback += key => { }; } _runMutex.ReleaseMutex(); }
private KeystrokeHooker InstallKeystrokeHooker() { var converter = new Models.KeyConverter(); var keystrokeHooker = new KeystrokeHooker(); keystrokeHooker.Callback += key => { if (!_alarm.Triggered) { return; } BeamgunState.AppendToKeyLog(converter.Convert(key)); }; return(keystrokeHooker); }
public BeamgunViewModel(Window mainWindow) { BeamgunState = new BeamgunState { MainWindowVisibility = Visibility.Hidden }; BeamgunState.Disabler = new Disabler(BeamgunState); BeamgunState.Disabler.Enable(); DisableCommand = new DisableCommand(this); TrayIconCommand = new TrayIconCommand(this); LoseFocusCommand = new DeactivatedCommand(this); ResetCommand = new ResetCommand(this); ExitCommand = new ExitCommand(this); _workstationLocker = new WorkstationLocker(); const uint repeatInterval = 10; var converter = new KeyConverter(); _keystrokeHooker = new KeystrokeHooker(); _alarm = new Alarm(repeatInterval, BeamgunState); _alarm.AlarmCallback += () => { BeamgunState.MainWindowState = WindowState.Normal; BeamgunState.MainWindowVisibility = Visibility.Visible; BeamgunState.SetGraphicsAlert(); if (BeamgunState.StealFocus) { StealFocus(); } }; var windowHandle = new WindowInteropHelper(mainWindow).Handle; _usbMonitor = new UsbMonitor(windowHandle); _usbMonitor.DeviceAdded += () => { BeamgunState.AppendToAlert("USB device inserted."); _alarm.Trigger("Alerting on USB device insertion."); if (!BeamgunState.LockWorkStation) { return; } var result = _workstationLocker.Lock(); var message = result ? "Successfully locked the workstation." : "Could not lock the workstation."; BeamgunState.AppendToAlert(message); }; _usbMonitor.DeviceRemoved += () => { BeamgunState.AppendToAlert("USB device removed."); }; _keystrokeHooker.Callback += key => { if (!_alarm.Triggered) { return; } BeamgunState.AppendToKeyLog(converter.Convert(key)); }; }