Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi SendInput - koordinaten x/y funtionnieren nicht (https://www.delphipraxis.net/118462-sendinput-koordinaten-x-y-funtionnieren-nicht.html)

smallsmoker 8. Aug 2008 00:28


SendInput - koordinaten x/y funtionnieren nicht
 
Hallo DP,
wenn ich eine mausbewegung nachbilden will benutzte ich MSDN-Library durchsuchenSendInput

mithilfe folgendes codes:

Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var
  Inp: TInput;
begin
  setcursorpos(900,350);

  Inp.Itype := INPUT_MOUSE;
  Inp.mi.dwFlags := MOUSEEVENTF_RIGHTDOWN;
  Inp.mi.dx := 900;
  Inp.mi.dy := 350;
  Inp.mi.time := 0;
  Inp.mi.dwExtraInfo := 0;
  SendInput(1, Inp, SizeOf(Inp));

  Inp.Itype := INPUT_MOUSE;
  Inp.mi.dwFlags := MOUSEEVENTF_RIGHTUP;
  Inp.mi.dx := 900;
  Inp.mi.dy := 350;
  Inp.mi.time := 0;
  Inp.mi.dwExtraInfo := 0;
  SendInput(1, Inp, SizeOf(Inp));

end;
das funktioniert auch wunderbar, jedoch muss ich den Maus-Cursor mit setcursorpos positionieren.
Eigentlich sollte das auch ohne funtionieren da die x und die y koordinarten ja angegeben wurden,
das dies nicht so einfach funktioniert ist bekannt:

Zitat:

Zitat:

I am really trying to use the SendInput to sent the input to the mouse. I think it is with this function I am having the problem. I have the coordinates of where I want the mouseclick to occur, but I cannot seem to make the mouse click on those coordinates.

I remember having trouble with this, however i ended up coming back to mouse_event. The conversion of coordinates is a bit weird to me (it's not something i've used much), however this will click at 500 x 500:

Public Declare Sub mouse_event Lib "user32"_
(ByVal dwFlags As Long, ByVal dX As Long, ByVal dY As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Public Const MOUSEEVENTF_MOVE = &H1 ' mouse move
Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Public Const MOUSEEVENTF_WHEEL = &H800 ' wheel button rolled
Public Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move

Public Sub ClickButton()
destX = 500
destY = 500
destX = destX * 65535 / Screen.Width * Screen.TwipsPerPixelX
destY = destY * 65535 / Screen.Height * Screen.TwipsPerPixelY

mouse_event MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE + MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, destX, destY, 0, 0
End Sub
wobei dies die wichtigen Zeilen sind:
Zitat:

destX = 500
destY = 500
destX = destX * 65535 / Screen.Width * Screen.TwipsPerPixelX
destY = destY * 65535 / Screen.Height * Screen.TwipsPerPixelY
und

Zitat:

MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE + MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP
was für meine zwecken
Inp.mi.dwFlags := MOUSEEVENTF_RIGHTDOWN or MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE;
entspricht auch kein problem.

ich habe schon gegoogelt aber leider weiß ich nicht wie ich Screen.TwipsPerPixelY/Screen.TwipsPerPixelX in Delphi benutzen soll

ich hoffe auf eure Hilfe

mfg smallsmoker

omata 8. Aug 2008 02:08

Re: SendInput - koordinaten x/y funtionnieren nicht
 
Was spricht gegen folgendes...
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);

  procedure Delay(ATime:Integer);
  var Start : integer;
  begin
    Start := GetTickCount;
    repeat
      Application.ProcessMessages;
    until abs(GetTickCount) - Start > ATime;
  end;

  procedure MouseClick(X, Y:cardinal);
  var
    Inp: TInput;
    Point:TPoint;
  begin
    Inp.Itype := INPUT_MOUSE;
    Inp.mi.dx := 0;
    Inp.mi.dy := 0;
    Inp.mi.time := 0;
    Inp.mi.dwExtraInfo := 0;
    Point:=Mouse.CursorPos;
    repeat
      SetCursorPos(X, Y);
      Application.ProcessMessages;
    until (Mouse.CursorPos.X = X) and (Mouse.CursorPos.Y = Y);
    Inp.mi.dwFlags := MOUSEEVENTF_RIGHTDOWN;
    SendInput(1, Inp, SizeOf(Inp));
    Delay(20);
    Inp.mi.dwFlags := MOUSEEVENTF_RIGHTUP;
    SendInput(1, Inp, SizeOf(Inp));
    repeat
      SetCursorPos(Point.X, Point.Y);
      Application.ProcessMessages;
    until (Mouse.CursorPos.X = Point.X) and (Mouse.CursorPos.Y = Point.Y);
  end;

begin
  MouseClick(900, 350);
end;

smallsmoker 8. Aug 2008 12:05

Re: SendInput - koordinaten x/y funtionnieren nicht
 
naja, klingt dumm aber ich möchte es eben gerne die maus mit sendinput positionieren :)
und ich habe ja auch eine lösung vorgelegt nur kann ich die nicht verwenden da sie nicht in delphi ist :/

also wenn mir jemand das hier:
Zitat:

Screen.TwipsPerPixelY
bzw.
Screen.TwipsPerPixelX
in delphi übersetzen könnte wäre ja alles geritzt :)

aber danke für deinen lösungvorschlag

mfg smallsmoker

smallsmoker 8. Aug 2008 13:29

Re: SendInput - koordinaten x/y funtionnieren nicht
 
Ich habe die Lösung nun selbst gefunden:

Delphi-Quellcode:
procedure Tfrmmain.btnMouse_ClickClick(Sender: TObject);
var
  Inp: TInput;
begin

  Inp.Itype := INPUT_MOUSE;
  Inp.mi.dwFlags := MOUSEEVENTF_RIGHTDOWN or MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE;
  Inp.mi.dx := round(900 * (65535 / Screen.Width));
  Inp.mi.dy := round(350 * (65535 / Screen.Height));
  Inp.mi.time := 0;
  Inp.mi.dwExtraInfo := 0;
  SendInput(1, Inp, SizeOf(Inp));

  Inp.Itype := INPUT_MOUSE;
  Inp.mi.dwFlags := MOUSEEVENTF_RIGHTUP or MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE;
  Inp.mi.dx := round(900 * (65535 / Screen.Width));
  Inp.mi.dy := round(350 * (65535 / Screen.Height));
  Inp.mi.time := 0;
  Inp.mi.dwExtraInfo := 0;
  SendInput(1, Inp, SizeOf(Inp));

end;
dieser Code würde einen click mit der rechten maustaste an den koordinaten (x: 900 | y: 350) ausführen.

mfg smallsmoker

p.s.: sry für den doppelpost


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:01 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz