问题
Just started reading on Reactive extensions. I am trying to watch a simple left mouse button click on my winform. Meaning anywhere there is a click (on any control on the form including the form) I just want to display a message "Click detected". So far I have
var mouseDown = Observable.FromEvent<MouseButtonEventArgs>(frmMain, "MouseDown");
//missing code please fill here
mouseDown.Subscribe(() => Debug.WriteLine("left click detected.");
I know the first line will detect any mouse event. I want just the left mouse button click. Please post working code so I can understand this better. Right now in a tailspin with buzzwords I have never used before like .takeuntil etc.. Further refining my question. What is the Rx equivalent of
protected override void WndProc(ref Message m)
{
Console.Writeline("{0}", m.Msg);
}
That should observe every observable mouse or keyboard event. thank you
回答1:
Sorry, I'm not sure if thats working code (can't try it now) but it should get you started.
var mouseDown = Observable.FromEvent<MouseButtonEventArgs>(frmMain, "MouseDown")
.Where(x => x.LeftButton == MouseButtonState.Pressed);
mouseDown.Subscribe(() => Debug.WriteLine("left click detected.");
来源:https://stackoverflow.com/questions/6298496/left-mouse-button-click-detect-on-winform-using-reactive-extensions-iobservable