0

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

Gullu
  • 3,477
  • 7
  • 43
  • 70
  • The Rx pre-release documentation has just been posted today: http://msdn.microsoft.com/en-us/library/hh242982(v=VS.103).aspx. You should probably take a look at that, and see the Rx Forums. – Richard Anthony Hein Jun 14 '11 at 19:01

1 Answers1

3

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.");
Christoph
  • 26,519
  • 28
  • 95
  • 133
  • thanks Chris. var mouseDown = Observable.FromEvent(this,"MouseDown") Compiler error on this. I am trying this code on a button click event on a form. this refers to the form. Intellisense does not show MouseButtonEventArgs so I am trying MouseEventArgs. I have now downloaded & installed the rx sdk (vs 2010, .net 4.0), added the system.reactive ref. There is only one book on Reactive extensions on Amazon. That too not yet released. for now i am studying from http://stackoverflow.com/questions/1596158/good-introduction-to-the-net-reactive-framework – Gullu Jun 10 '11 at 16:00
  • iam gueesing i dont see MouseButtonEventArgs because iam not using wpf. This issue is winforms related. thanks – Gullu Jun 11 '11 at 16:55