?
Solved

Animated movement of my cursor

Posted on 2002-06-07
3
Medium Priority
?
330 Views
Last Modified: 2010-04-04
I know how can I move my mouse, but I wish to create an animated movement and not just a jump to the new position.
Can give me some codes for how can I move animated (step by step )the cursor from Point1 to Point2?

Nick
0
Comment
Question by:ginsonic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7064043
a sample to move the mouse in 250 steps

procedure TForm1.Button1Click(Sender: TObject);
var
  p : Tpoint;
  I : Integer;
  stepx, Stepy : Integer;
begin
  getcursorpos(p);
  setcursorPos(0,0);
  stepx := screen.width div 250;
  stepy := screen.height div 250;
  for i := 1 to 250 do
    setcursorpos(stepx*i,stepy*i);
  setcursorpos(p.x,p.y);
end;

meikl ;-)
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 400 total points
ID: 7064833
hello, here's some code that will move the cursor using a Multi Media Timer, and some Trig functions to calculate the distance and relative X and Y movement of the cursor.


uses mmsystem, Math;

private
    { Private declarations }
    EndPos, StartPos, Mover: TPoint;
    PixelMov: Word;
    Radian1: Extended;
    TimerID: Cardinal;
    TimeCaps: TTimeCaps;
    procedure MoveCursor;


procedure TForm1.FormCreate(Sender: TObject);
begin
TimeGetDevCaps(@TimeCaps, sizeof(TimeCaps));
{the line above is NEEDED to set up your MultiMedia Timer
which is much better for movement, animation, sprite drawing than
a TTimer.}
end;


procedure TForm1.FormDestroy(Sender: TObject);
var
i: Integer;
begin
{the MM Timer is running outside of your app, so be sure to kill it}
timeKillEvent(TimerID);
TimeEndPeriod(TimeCaps.wPeriodMin);
end;


procedure TimerProc(uTimerID, uMessage: cardinal; dwUser, dw1, dw2: integer); stdcall;
begin
Form1.MoveCursor;
{this procedure is called no matter if the code from the last call has finished or not.
so it's probally better to not run any code here but just call another procedure.
With only one timer, I don't need to use any of the Params here either}
end;

procedure TForm1.MoveCursor;
begin
SetCursorPos(Round(StartPos.x-Cos(Radian1)*(PixelMov*Mover.x)),
             Round(StartPos.y-Sin(Radian1)*(PixelMov*Mover.x)));
Inc(Mover.x);
if (Mover.x > Mover.y) or (Mover.x > 3000) then
  begin
  timeKillEvent(TimerID);
  TimeEndPeriod(TimeCaps.wPeriodMin);
  SetCursorPos(EndPos.x, EndPos.y)
  end;
end;

procedure TForm1.sbut_MoveCurClick(Sender: TObject);
var
i: Integer;
Interval,Accur: Word;
begin
GetCursorPos(StartPos);
EndPos.x := Screen.Width div 2;
EndPos.y := Screen.Height div 2;
PixelMov := 13;
{the PixelMov is the amount of pixel movement for ONE call to MoveCursor}
Mover.x := 0;
Mover.y := Round(Sqrt(SumOfSquares([abs(EndPos.y-StartPos.y),abs(EndPos.x-StartPos.x)]))) div PixelMov;
Radian1 := DegToRad(180 * (1 + ArcTan2(EndPos.y-StartPos.y, EndPos.x-StartPos.x) / Pi));
timeKillEvent(TimerID);
TimeEndPeriod(TimeCaps.wPeriodMin);
TimeBeginPeriod(TimeCaps.wPeriodMin);

Interval := 34;
{intervals less than 20 use up alot of processor time, it's better to Increase
PixelMove than decrease Interval}
Accur := Interval div 2;
if Accur < TimeCaps.wPeriodMin then
Accur := TimeCaps.wPeriodMin;
if Accur > TimeCaps.wPeriodMax then
Accur := TimeCaps.wPeriodMax;
TimerID := TimeSetEvent(Interval, Accur, @TimerProc, 10, TIME_PERIODIC);
end;

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

the mmtimer will keep running even if there is a System Modal dialog Box up (Ctrl+Alt+Del), it does not matter so much with
cursor movement, but other things might. This works for me,
Wes
0
 
LVL 9

Author Comment

by:ginsonic
ID: 7092705
Slick812,
Can you help me to do same work without a timmer ?
Alike While ...
Anothers 100 points for that.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question