Determine mouse movement direction

  • Thread starter Thread starter Paul L
  • Start date Start date
P

Paul L

Anyone know a quick way of determining which direction the mouse cursor is
moving (ie. up, down, left, right) from a specified origin?

Thanks,
Paul L
 
All you would need to do is take the origin (where the mouse was) and
take the current mouse position, then figure out what the greatest
difference axis is: x or y something like this:

if (System.Math.Abs(origin.X - mouse.X) > System.Math.Abs(origin.Y -
mouse.Y))
{
// change in x is greater, now find left or right
if ((origin.X - mouse.X) < 0)
{
return "right";
}
else
{
return "left";
}
}
else
{
// change in y is greater, now find up or down
if ((origin.Y - mouse.Y) < 0)
{
return "up";
}
else
{
return "down";
}
}
 
Back
Top