Mouse Program???
2 messages in this thread
I would like some ideas on developing a program to monitor the mouse
x,y coordinates as the mouse is moved by a user. I would like to be
able to detect: a. which direction the mouse is being moved in. (I
know how to do this for up down right left, but what about
diagonally, etc. b. how fast the mouse is being moved. I am not
looking for commands in a specific language so much as general,
"generic" descriptions of how I might go about developing such
routines in whatever language I choose. Thanks for help/suggestions.
George Roland
I hope this is helpful:
If you are using the gameport.device to monitor the mouse, you will
receive events in the form of an InputEvent structure. This contains x and y
coordinates. I think these are relative to the last position i.e. delta, but no
doubt someone will correct me if this is incorrect. Anyway, what you need are
delta values so you can tell how far the mouse was moved and in what direction.
If the values you have are absolute, delta values can be calculated from two
coordinate pairs (x1,y1) = last position , (x2,y2) = this position as follows:
deltax = x2 – x1
deltay = y2 – y1
With these values you can ascertain the 'slope' the mouse was moved along.
This is the same as calculating the gradient: m = deltay / deltax ( = rise /
run ). Movement along this line was left-to-right if deltax is positive and
top-to-bottom if deltay is positive.
Speed is expressed as distance/time (eg km/h), so you need values for
distance and time. The distance the mouse has moved between two readings can
be calculated using the deltax and deltay values as follows:
________________________
d = /(deltax)^2) + (deltay)^2
(distance = the square root of deltax squared + deltay squared)
As for time, InputEvents have a TimeStamp field, so if time1 is the time of the
last InputEvent, and time2 the time of this one, t = time2 – time1. If you are
not getting your coordinates from InputEvents, perhaps you could read the
coordinates at regular intervals (eg using the timer.device), the length of the
intervals being the value you use for time.
I hope that this is all clear and (more importantly) what you're after.
James.