Google
Showing posts with label cursor. Show all posts
Showing posts with label cursor. Show all posts

Wednesday, March 14, 2007

get and set mouse position

procedure TForm1.Button1Click(Sender: TObject);
var
MausPos: TPoint;
begin
GetCursorPos(MausPos);
label1.Caption := IntToStr(MausPos.x);
label2.Caption := IntToStr(MausPos.y);
end;

// Set mouse position to (x,y)

procedure TForm1.Button2Click(Sender: TObject);
begin
SetCursorPos(600, 600);
end;

Thursday, March 8, 2007

move the cursor to the currently focused control

procedure TForm1.Button1Enter(Sender: TObject);
var
cntrl: TControl;
xCent, yCent: Integer;
point: TPoint;
begin
cntrl := TControl(Sender);
xCent := cntrl.Left + (cntrl.Width div 2);
yCent := cntrl.Top + (cntrl.Height div 2);
point := ClientToScreen(Point(xCent, yCent));
SetCursorPos(point.X,point.Y);
end;