void OnKeyUp(object Sender, KeyEventArgs Args) { if (!_settings.Display) { _records.Clear(); return; } var record = new KeyRecord(Args, _keymap); var display = record.Display; if (display == _keymap.Control || display == _keymap.Alt || display == _keymap.Shift) { if (_records.Last?.Display == display) { _records.Last = new RepeatKeyRecord(record); } else if (_records.Last is RepeatKeyRecord repeat && repeat.Repeated.Display == display) { repeat.Increment(); } else if (_modifierSingleDown) { _records.Add(record); } }
void OnKeyUp(object Sender, KeyEventArgs Args) { if (!_keystrokesSettings.Display) { _records.Clear(); return; } var record = new KeyRecord(Args); if (record.Display == "Ctrl" || record.Display == "Alt" || record.Display == "Shift") { if (_records.Last?.Display == record.Display) { _records.Last = new RepeatKeyRecord(record); } else if (_records.Last is RepeatKeyRecord repeat && repeat.Repeated.Display == record.Display) { repeat.Increment(); } else { _records.Add(record); } }
public RepeatKeyRecord(KeyRecord Repeated, KeystrokesSettings Settings) { this.Repeated = Repeated; _settings = Settings; Increment(); }
TextWriter InitKeysToTextFile(string FileName, Func <TimeSpan> Elapsed) { var dir = Path.GetDirectoryName(FileName); var fileNameWoExt = Path.GetFileNameWithoutExtension(FileName); var targetName = $"{fileNameWoExt}.keys.txt"; var path = dir == null ? targetName : Path.Combine(dir, targetName); var keystrokeFileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); var textWriter = new StreamWriter(keystrokeFileStream); _hook.KeyDown += (S, E) => { if (!_keystrokesSettings.Display) { return; } var record = new KeyRecord(E, _keymap); _textWriter.WriteLine($"{Elapsed.Invoke()}: {record.Display}"); }; return(textWriter); }
public KeyStep(KeystrokesSettings Settings, KeyRecord KeyRecord) { _settings = Settings; // TODO: Handle Modifiers keys on KeyUp like in KeyOverlay Text = KeyRecord.Display; _mergeable = Text.Length == 1; }
/// <summary> /// Creates a new instance of <see cref="MouseKeyHook"/>. /// </summary> public MouseKeyHook(MouseClickSettings MouseClickSettings, KeystrokesSettings KeystrokesSettings, KeymapViewModel Keymap, string FileName, Func <TimeSpan> Elapsed) { _mouseClickSettings = MouseClickSettings; _keystrokesSettings = KeystrokesSettings; _keymap = Keymap; _hook = Hook.GlobalEvents(); _hook.MouseDown += (S, E) => { _mouseClicked = true; _mouseButtons = E.Button; }; _hook.MouseUp += (S, E) => _mouseClicked = false; if (KeystrokesSettings.SeparateTextFile) { _elapsed = Elapsed; var dir = Path.GetDirectoryName(FileName); var fileNameWoExt = Path.GetFileNameWithoutExtension(FileName); var targetName = $"{fileNameWoExt}.keys.txt"; var path = dir == null ? targetName : Path.Combine(dir, targetName); _keystrokeFileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); _textWriter = new StreamWriter(_keystrokeFileStream); _hook.KeyDown += (S, E) => { if (!_keystrokesSettings.Display) { return; } var record = new KeyRecord(E, _keymap); _textWriter.WriteLine($"{_elapsed.Invoke()}: {record.Display}"); }; } else { _records = new KeyRecords(KeystrokesSettings.HistoryCount); _hook.KeyDown += OnKeyDown; _hook.KeyUp += OnKeyUp; } }
void OnKeyUp(object Sender, KeyEventArgs Args) { if (Args.KeyCode == Keys.W) { _keyVector.wPressed = false; } if (Args.KeyCode == Keys.A) { _keyVector.aPressed = false; } if (Args.KeyCode == Keys.S) { _keyVector.sPressed = false; } if (Args.KeyCode == Keys.D) { _keyVector.dPressed = false; } if (!_keystrokesSettings.Display) { _records.Clear(); return; } var record = new KeyRecord(Args, _keymap); var display = record.Display; if (display == _keymap.Control || display == _keymap.Alt || display == _keymap.Shift) { if (_records.Last?.Display == display) { _records.Last = new RepeatKeyRecord(record); } else if (_records.Last is RepeatKeyRecord repeat && repeat.Repeated.Display == display) { repeat.Increment(); } else if (_modifierSingleDown) { _records.Add(record); } }
IObservable <IRecordStep> Observe(IMouseKeyHook Hook, CancellationToken CancellationToken, out IObservable <Unit> ShotObservable) { var subject = new Subject <IRecordStep>(); var shotSubject = new Subject <Unit>(); ShotObservable = shotSubject; void OnNext(IRecordStep NextStep) { if (_lastStep != null) { if (_lastStep.Merge(NextStep)) { return; } subject.OnNext(_lastStep); } shotSubject.OnNext(Unit.Default); _lastStep = NextStep; } Hook.MouseClick += (S, E) => { var step = new MouseClickStep(_mouseClickSettings, _keystrokesSettings, E, _keymap); OnNext(step); }; Hook.MouseDoubleClick += (S, E) => { var step = new MouseClickStep(_mouseClickSettings, _keystrokesSettings, E, _keymap); OnNext(step); }; Hook.MouseDragStarted += (S, E) => { var step = new MouseDragBeginStep(E.Location, _mouseClickSettings, _keystrokesSettings, _keymap); OnNext(step); }; Hook.MouseDragFinished += (S, E) => { var step = new MouseDragStep(E.Location, _mouseClickSettings, _keystrokesSettings, _keymap); OnNext(step); }; if (_stepsSettings.IncludeScrolls) { // TODO: Event is not firing for touchpad scroll Hook.MouseWheel += (S, E) => { var step = new ScrollStep(E, _mouseClickSettings, _keystrokesSettings, _keymap); OnNext(step); }; } Hook.KeyDown += (S, E) => { _modifierSingleDown = false; var record = new KeyRecord(E, _keymap); var display = record.Display; if (display == _keymap.Control || display == _keymap.Alt || display == _keymap.Shift) { _modifierSingleDown = true; } else { OnNext(new KeyStep(_keystrokesSettings, record)); } }; Hook.KeyUp += (S, E) => { var record = new KeyRecord(E, _keymap); var display = record.Display; if (display == _keymap.Control || display == _keymap.Alt || display == _keymap.Shift) { if (_modifierSingleDown) { OnNext(new KeyStep(_keystrokesSettings, record)); } } }; CancellationToken.Register(() => { shotSubject.OnCompleted(); subject.OnNext(_lastStep); subject.OnCompleted(); }); return(subject .Where(M => _recording)); }
public RepeatKeyRecord(KeyRecord Repeated) { this.Repeated = Repeated; Increment(); }
void OnKeyPressed(object sender, KeyEventArgs e) { if (_output.Length > Settings.Instance.Keystrokes_MaxLength) { _output = ""; } var keyRecord = new KeyRecord(e); string key; switch (e.KeyCode) { case Keys.Shift: case Keys.ShiftKey: case Keys.LShiftKey: case Keys.RShiftKey: key = "Shift"; break; case Keys.Control: case Keys.ControlKey: case Keys.LControlKey: case Keys.RControlKey: key = "Ctrl"; break; case Keys.Alt: case Keys.Menu: case Keys.LMenu: case Keys.RMenu: key = "Alt"; break; case Keys.LWin: case Keys.RWin: key = "Win"; break; default: key = keyRecord.ToString(); if (keyRecord.Control || keyRecord.Alt) { _output = ""; } break; } if (key.Length > 1 || (_lastKeyRecord != null && (_lastKeyRecord.ToString().Length > 1 || (keyRecord.TimeStamp - _lastKeyRecord.TimeStamp).TotalSeconds > Settings.Instance.Keystrokes_MaxSeconds))) { _output = ""; } _output += key; _lastKeyRecord = keyRecord; }