I was handling yet another KeyDown event in a user control when I wondered if it existed a library for typing fluent code for handling event like
editor.When(Keys.F).IsDown().With(Keys.Control).Do((sender, e) => ShowFindWindow());
Does that exist?
I downloaded the Reactive Extension Framework for the .Net Framework 3.5 SP1.
I was able to do the same:
Observable.FromEvent<KeyEventArgs>(this, "KeyDown")
.Where(e => e.EventArgs.KeyCode == Keys.F && e.EventArgs.Modifiers == Keys.Control)
.Subscribe(e => MessageBox.Show(e.EventArgs.KeyData.ToString()));
This is some pretty powerful stuff.
.NET 4 will introduce the reactive framework (IObservable<T>
, IObserver<T>
and helper extension types) which should offer exactly this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With