This project is read-only.

Example - Using Touchless to control the mouse cursor

Oct 16, 2009 at 1:26 PM
Edited Oct 16, 2009 at 1:27 PM


You guys were a big help so thought I'd start to try and give back a bit from what we've learnt over the last few months using Touchless. First, a very simple example of how to move the mouse cursor using a marker

void Player1_OnChange(object sender, MarkerEventArgs e)



Cursor.Position = new System.Drawing.Point((int)(e.EventData.X * 4.031), (int)(e.EventData.Y * 4.24));


where the *4.031 is the difference between our picturebox control that has the webcam feed and the actual screen resolution, in this case we have a video feed in a picturebox of size 254 by 181 pixels, and a screen of 1024 x 768. Divide 1024 by 254 to get the 4.031 multiplier, this just means you can move it ovr the whole screen without having to make your video feed full screen. In our case we have a small video feed and a game board covering the rest of the screen and this lets our markers move the mouse to the correct tiles.



Oct 17, 2009 at 4:45 AM

Cool; thanks for your tips, Andrew! That's a really concise explanation to getting this working. You can also handle a wider variety of resolutions using Screen.PrimaryScreen.Bounds. Anyone that wants to just try this out or learn more about controlling a mouse with Touchless can check out MouseDemo in TouchlessDemo. I put that together with help from Predrag Tomasevic and the famous eFloh. It's not perfect (be careful using two markers to 'click'!), so any patches or other contributions to that demo are appreciated. I've had the best luck pointing the camera down at my desk, (maybe even slightly towards yourself) to capture smaller markers in a mousepad sized area. I've used dry erase marker caps on my fingertips and even M&Ms as decent markers for this. It's a nice quick and dirty multi-'touch' 'pad'.

- Mike