예제 #1
0
        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);
                }
            }
예제 #2
0
        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);
                }
            }
예제 #3
0
        public RepeatKeyRecord(KeyRecord Repeated, KeystrokesSettings Settings)
        {
            this.Repeated = Repeated;
            _settings     = Settings;

            Increment();
        }
예제 #4
0
        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);
        }
예제 #5
0
파일: KeyStep.cs 프로젝트: evincee/Captura
        public KeyStep(KeystrokesSettings Settings,
                       KeyRecord KeyRecord)
        {
            _settings = Settings;

            // TODO: Handle Modifiers keys on KeyUp like in KeyOverlay
            Text = KeyRecord.Display;

            _mergeable = Text.Length == 1;
        }
예제 #6
0
        /// <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;
            }
        }
예제 #7
0
        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);
                }
            }
예제 #8
0
        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));
        }
예제 #9
0
        public RepeatKeyRecord(KeyRecord Repeated)
        {
            this.Repeated = Repeated;

            Increment();
        }
예제 #10
0
        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;
        }