Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Animated movement of my cursor

Posted on 2002-06-07
3
Medium Priority
?
335 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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