MouseMove in das Zentrum der Rechteck Koordinate Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

effel
Posts: 544
Joined: 16 Jan 2018, 13:34

MouseMove in das Zentrum der Rechteck Koordinate

12 Sep 2020, 11:19

Hallo,
mit folgendem Code von Rohwedder markiere ich einen Rechteck Bereich vom Bildschirm

Code: Select all

; Should work with all current AHK versions/builds 
; https://www.autohotkey.com/boards/viewtopic.php?p=244687#p244687
#NoEnv
SetBatchLines, -1 ; For speed in general
SetWinDelay, -1   ; For speed of WinMove
BW := 3           ; Border width (and height) in pixels
BC := "Red"       ; Border color
; ______________________________________________________________________________________________________________________
FirstCall := True
CoordMode, Mouse, Screen
Gui, -Caption +ToolWindow +LastFound +AlwaysOnTop
Gui, Color, %BC%
Return
; ______________________________________________________________________________________________________________________
Esc::
ExitApp
; ______________________________________________________________________________________________________________________
+LButton::
    MouseGetPos, OriginX, OriginY
	WinGetActiveStats, Title, WindowWidth, WindowHeight, WindowX, WindowY
    SetTimer, DrawRectangle, 10
Return
; ______________________________________________________________________________________________________________________
+LButton Up::
   SetTimer, DrawRectangle, Off
   FirstCall := True
   Gui, Cancel
   ToolTip

ClipBoard := X1 "`," Y1 "`," W1 "`," H1 ; Beispiel: 1523,846,301,74

   MsgBox, 0, Coordinates, X = %X1%  -  Y = %Y1%  -  W = %W1%  -  H = %H1%
   MsgBox, 0, relative: %Title%, % "X = " X1-WindowX  "  -  Y = " Y1-WindowY
Return
; ______________________________________________________________________________________________________________________
DrawRectangle:
   MouseGetPos, X2, Y2
   ; Has the mouse moved?
   If (XO = X2) And (YO = Y2)
      Return
   Gui, +LastFound
   XO := X2, YO := Y2
   ; Allow dragging to the left of the click point.
   If (X2 < OriginX)
      X1 := X2, X2 := OriginX
   Else
      X1 := OriginX
   ; Allow dragging above the click point.
   If (Y2 < OriginY)
      Y1 := Y2, Y2 := OriginY
   Else
      Y1 := OriginY
   ; Draw the rectangle
   W1 := X2 - X1, H1 := Y2 - Y1
   W2 := W1 - BW, H2 := H1 - BW
   WinSet, Region, 0-0 %W1%-0 %W1%-%H1% 0-%H1% 0-0  %BW%-%BW% %W2%-%BW% %W2%-%H2% %BW%-%H2% %BW%-%BW%
   If (FirstCall) {
      Gui, Show, NA x%X1% y%Y1% w%W1% h%H1%
      FirstCall := False
   }
   WinMove, , , X1, Y1, W1, H1
   ; ToolTip, %X1% - %Y1% - %X2% - %Y2%
Return
Mit diesem Einzeiler speichere ich die Koordinaten
ClipBoard := X1 "`," Y1 "`," W1 "`," H1

Wie erhalte ich das Zentrum des Rechtecks [3313,955,242,68]. Ich möchte mit der Maus dort klicken
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: MouseMove in das Zentrum der Rechteck Koordinate

12 Sep 2020, 14:28

Code: Select all

MouseMove, X1+(W1/2), Y1+(H1/2) ; Done
effel
Posts: 544
Joined: 16 Jan 2018, 13:34

Re: MouseMove in das Zentrum der Rechteck Koordinate  Topic is solved

12 Sep 2020, 19:17

Danke BoBo das funktioniert

Code: Select all

+LButton Up::
   SetTimer, DrawRectangle, Off
   FirstCall := True
   Gui, Cancel
   ToolTip

;	ClipBoard := X1 "`," Y1 "`," W1 "`," H1 "`," X1-WindowX "`," Y1-WindowY 
; ergebnis: 456,293,1164,577,374,301
	ClipBoard := X1+(W1/2) "`," Y1+(H1/2) 
; ergebnis: 838.500000,535.500000
sleep, 1000
MouseClick, left, 3441.500000,996.000000

 ;  MsgBox, 0, Coordinates, X = %X1%  -  Y = %Y1%  -  W = %W1%  -  H = %H1%
 ;  MsgBox, 0, relative: %Title%, % "X = " X1-WindowX  "  -  Y = " Y1-WindowY
Return
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: MouseMove in das Zentrum der Rechteck Koordinate

13 Sep 2020, 04:46

Ist mir neu, das ein als String gesetztes Komma escaped wird?!! :think:

1+(W1/2) "`," vs. 1+(W1/2) ","
effel
Posts: 544
Joined: 16 Jan 2018, 13:34

Re: MouseMove in das Zentrum der Rechteck Koordinate

13 Sep 2020, 08:28

es wird zumindest nicht bemängelt
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: MouseMove in das Zentrum der Rechteck Koordinate

14 Sep 2020, 03:37

... ist aber zumindest unnötig. Kommata innerhalb von Strings in Ausdrücken "..." haben keine besondere Bedeutung. Ein ; mit vorangestelltem Leerzeichen führt dagegen regelmäßig zu Problemen, weil es zu einem sehr frühen Zeitpunkt als Zeilenendekommentar gewertet wird. Umgebende Anführungszeichen werden da noch nicht beachtet.

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 87 guests