473,480 Members | 3,062 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Determine mouse movement direction

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
Nov 16 '05 #1
3 9321
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";
}
}
Nov 16 '05 #2
You one thing to add - you can get the current mouse position with
MousePosition.X and MousePosition.Y.

Regards,
Peter Jausovec
(http://blog.jausovec.net)

"Benny Raymond" <be***@pocketrocks.com> je napisal v sporocilo
news:%2****************@TK2MSFTNGP10.phx.gbl ...
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";
}
}

Nov 16 '05 #3
Thanks for the help guys.

Paul L

"Peter Jausovec" <pe***@jausovec.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
You one thing to add - you can get the current mouse position with
MousePosition.X and MousePosition.Y.

Regards,
Peter Jausovec
(http://blog.jausovec.net)

"Benny Raymond" <be***@pocketrocks.com> je napisal v sporocilo
news:%2****************@TK2MSFTNGP10.phx.gbl ...
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";
}
}



Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1662
by: John | last post by:
Hi all: I have an application that hides itself and displays an icon in the system tray. Is it possible for this application to detect keystrokes and/or mouse movements while hidden/minimized....
1
19040
by: Benny Raymond | last post by:
In my attempt to make a macro recording program where i can then playback mouse movements i'm running into a big problem: I'm trying to simulate the movement of the mouse to a point on the...
0
1427
by: Johann Blake | last post by:
I created my own toolbar from scratch using PictureBoxes. I use the MouseEnter and MouseMove events to change the image on the PictureBox controls so that it makes the "button" look selected,...
3
3595
by: garyusenet | last post by:
I have a programme written in C++, the programme is unmanaged and is an executable, i don't have any source code. I'm writing a C# program. I want to (a) start the programme minimized. (b) send...
4
6947
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be programmed. Stop snickering!!! I didn't do it...I...
5
2303
by: hurricane_number_one | last post by:
I am creating a simple server application, that will listen for incoming mouse coordinates and then move the mouse accordingly. So basically it's like a very simple VNC server without and screen...
6
3069
by: c.k. | last post by:
I was wondering if there was a way to give mouse movement on an empty form some lag/delay? For instance, user moves mouse, and the cursor is 20ms (possible adjustable from some option) behind the...
5
4392
by: LurkB | last post by:
Hey , I wonder how and which programming language I can use to capture movement of a mouse on Linux screen (not just on a particular webpage user is on) like how VB, C#,C++, and J# can be used to...
0
7106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.