private static void HandleKeysFromEventPatternWithOperators() { var keyLogger = new EventedKeyWatcher(); var observable = Observable.FromEventPattern <KeyEventArgs>( keyLogger, nameof(EventedKeyWatcher.KeyLogged)); var operationObservable = observable .Select(e => e.EventArgs.Key) .Buffer(Program.BufferCount, Program.BufferSkip) .Delay(TimeSpan.FromSeconds(2)); using (var subscription = observable.Subscribe( pattern => { if (Program.CheckForTermination(pattern.EventArgs.Key)) { keyLogger.Cancel(); } })) { using (var operationSubscription = operationObservable.Subscribe( operationPattern => { Console.Out.WriteLine(operationPattern.ToArray()); })) { keyLogger.Listen(); } } }
private static void HandleKeysViaEvents() { var keyLogger = new EventedKeyWatcher(); keyLogger.KeyLogged += (s, e) => { Console.Write(e.Key); if (Program.CheckForTermination(e.Key)) { keyLogger.Cancel(); } }; keyLogger.Listen(); }
private static void HandleKeysFromEventPattern() { var keyLogger = new EventedKeyWatcher(); var observable = Observable.FromEventPattern <KeyEventArgs>( keyLogger, nameof(EventedKeyWatcher.KeyLogged)); using (var subscription = observable.Subscribe( pattern => { var key = pattern.EventArgs.Key; Console.Out.Write(key); if (Program.CheckForTermination(key)) { keyLogger.Cancel(); } })) { keyLogger.Listen(); } }