Capturing Mouse Movement
Many of you have probably seen "mouse meters" that track how many pixels the mouse has moved. I'm trying to do that but I can't figure out how to execute code every time there's a mousemove (on any control, let alone the entire screen). This is what I've gotten so far but it doesn't work. Any ideas?
| | namespace mmove { public partialclass Form1 : Form { int pxls = 0; public Form1() { InitializeComponent(); } privatevoid OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { pxls++; textBox1.Text = pxls.ToString(); } } }
|
If you want to capture mouse events when the mouse has moved away from your control, you'll need to set "capture" to on.
Try calling
this.Capture = true;
on your form's OnLoad override.
OK, but that seems to freeze my computer :p
I rewrote it slightly and I got a working program but it only counts while the mouse is in the application window. I have this.capture set as i was told... here's my complete code
| | namespace mmove { public partial class Form1 : Form { int pxls = 0; public Form1() { InitializeComponent(); } protected override void OnMouseMove(MouseEventArgs e) { pxls++; textBox1.Text = pxls.ToString(); } private void Form1_Load(object sender, EventArgs e) { this.Capture = true; } } } |
Hi,
You could try implementing
DirectX's Direct Input. It handles mouse moves all over the screen... And also you could capture keyboards, joystick and other input devices...
cheers,
Paul June A. Domag