예제 #1
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 += (sender, e) =>
            {
                if (!_keystrokesSettings.Display)
                {
                    return;
                }

                var record = new KeyRecord.KeyRecord(e, _keymap);

                _textWriter.WriteLine($"{elapsed.Invoke()}: {record.Display}");
            };

            return(textWriter);
        }
예제 #2
0
        void OnKeyUp(object sender, KeyEventArgs args)
        {
            if (!_keystrokesSettings.Display)
            {
                _records.Clear();

                return;
            }

            var record = new KeyRecord.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);
                }
            }
예제 #3
0
        public RepeatKeyRecord(KeyRecord repeated)
        {
            Repeated = repeated;

            Increment();
        }