public void Clear() { KeyPressEvents.Clear(); KeyDurEvents.Clear(); InProgressDurEvents.Clear(); _stopwatch.Reset(); _stopwatch.Stop(); }
// Check if the key is a key we care about, if so handle it public void RegisterEvent(Key key) { TimeSpan now = _stopwatch.Elapsed; // Start/Stop key was pressed if (key == PauseKey) { if (_stopwatch.IsRunning) { _stopwatch.Stop(); } else { _stopwatch.Start(); } } // A one off non duration key is pressed else if (PressKeys.Select(x => x.key).Contains(key)) { KeyDurEvents.Add(new KeyDurEvent(key, now, TimeSpan.MinValue)); //KeyPressEvents.Add(new KeyPressEvent(key, now)); } // A duration key is pressed, check if we already have that key in progress else if (DurKeys.Select(x => x.key).Contains(key)) { var durEvent = InProgressDurEvents.Find(x => x.Key == key); if (durEvent != default(KeyDurEvent)) // The pressed key was already in progress { KeyDurEvents.Add(new KeyDurEvent(key, durEvent.Start, now)); InProgressDurEvents.Remove(durEvent); } else { InProgressDurEvents.Add(new KeyDurEvent(key, now, TimeSpan.MinValue)); } } }