473,606 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ 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 9337
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.Ab s(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***@pocketro cks.com> je napisal v sporocilo
news:%2******** ********@TK2MSF TNGP10.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.Ab s(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******** ********@TK2MSF TNGP11.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***@pocketro cks.com> je napisal v sporocilo
news:%2******** ********@TK2MSF TNGP10.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.Ab s(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
1675
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. So the application is not loaded and visible, so mouse movements on the form won't work, I need the program to be able to detect mouse movement on the system level. Thanks in advance.
1
19135
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 screen. With my current code the mouse is only moving in the X direction and not in the Y direction (however my debug line is telling me that it's trying to move in the Y as well). I've read everything I could find online, tried some hacky ways of...
0
1433
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, pressed, disabled or unselected. What I noticed however is that if I move the mouse quick enough from one button to another or to some where other than the "toolbar", it is possible that the MouseLeave event never gets fired which results in the...
3
3603
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 keystrokes to the programme, and mouse strokes. Can you please tell me how I would do this assuming the programme is called "c:\programme.exe"
4
6960
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 just gotta fix it. I need to make some calculations on the measurements and VB6 is my language. Yes, the system mouse will corrupt the measurement, but it's an auditing function and that's acceptable.
5
2316
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 display. I have this basic part working. The problem is that response time is really bad. It seems like the server is not receiving the data fast enough to be able to move the mouse so that it appears to be in sync with the movement on the client...
6
3101
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 movement. So when user stops moving mouse, 20ms later the cursor itself stops moving... I tried using: Windows.Forms.Cursor.Current.Position = New System.Drawing.Point(x,y) and forms of sleep/timer events but cant seem to get it to work...
5
4397
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 detect mouse movement on windows screen. Thanks in advance L
0
8031
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7962
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6792
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5971
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3945
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2452
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 we have to send another system
1
1565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.