Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

50 pixel from mouse


  • Please log in to reply
5 replies to this topic
0mega
  • Members
  • 38 posts
  • Last active: Nov 15 2008 09:38 PM
  • Joined: 17 May 2007
Hey
How can I make line, that turn opposite direction of specific coordinate and follows mouse 1 pixel away from it ( so it is able to click too)
Line should be 20 pixel long
That example gif maybe tell that thing better ?
Posted Image

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
there is no easy way to draw arbitrary lines with AHK.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
engunneer is right, you need to use GDI with DllCalls. This is confusing, I never done this before. I took a quick look at the GDI line and curve functions reference and came up with this:

; points on centre screen
cx := A_ScreenWidth // 2
cy := A_ScreenHeight // 2

axis = 50 ; grid size
offset = 3 ; offset from mouse

CoordMode, Mouse ; set all coords relative to the screen

Gui, -Caption +LastFound +AlwaysOnTop +ToolWindow +Border
Gui, Color, White
Gui, Show, w%axis% h%axis%
WinSet, TransColor, 0xffffff ; make white background transparent
OnExit, GuiClose

Gui := WinExist()
DC := DllCall("GetDC", "UInt", Gui) ; create device context
Pen := DllCall("CreatePen", "UInt", 0, "UInt", 2, "UInt", 0) ; create pen
DllCall("SelectObject", "UInt", DC, "UInt", Pen) ; select pen

Loop {
	MouseGetPos, x, y
	If (x != lx or y != ly)
	{
		WinMove, x - axis - offset, y + offset
		;[color=violet]c := Sqrt((cx - x) ** 2 + (cy - y) ** 2)[/color] ; hypotenuse (using Pythagoras)
		;[color=violet]s := ASin((cy - y) / c) [/color]; sine angle
		g := (cy - y) / (cx - x) ; gradient
		; clear previously drawn line:
		DllCall("FloodFill", "UInt", DC, "UInt", 1, "UInt", 1, "UInt", 1)
		DllCall("MoveToEx", "UInt", DC, "UInt", 1, "UInt", -axis * g, "UInt", 0) ; start
		DllCall("LineTo", "UInt", DC, "UInt", 50, "UInt", axis * g + axis) ; end
		lx := x, ly := y
	}
	Sleep, 1
}
Return

~*Esc::
GuiClose:
DllCall("DeleteObject", "UInt", Pen)
DllCall("ReleaseDC", "UInt", Gui, "UInt", DC)
ExitApp

You can get rid of the border by changing the Gui options. My calculations aren't exactly correct, so you need to fix it using the information in the highlighted lines.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


0mega
  • Members
  • 38 posts
  • Last active: Nov 15 2008 09:38 PM
  • Joined: 17 May 2007
Thank you very much.

0mega
  • Members
  • 38 posts
  • Last active: Nov 15 2008 09:38 PM
  • Joined: 17 May 2007
-edited

0mega
  • Members
  • 38 posts
  • Last active: Nov 15 2008 09:38 PM
  • Joined: 17 May 2007
Just tried again to make it, but this time different..
But I dont understand those transform things :S

CoordMode,
SetBatchLines, -1
SetMouseDelay, -1
setWinDelay, 5

LButton::
Click down
SplashImage, C:\Documents and Settings\0mega\Työpöytä\Omega\Splashimages\Ringula.gif, B X3 Y3,,,Ringula
Loop
{
X :=946 
Y :=251
MouseGetPos, XX, YY
if (X-XX<0) {
DistanceX := XX-X
} else {
DistanceX := X-XX
}
if (Y-YY<0) {
DistanceY := YY-Y
} else {
DistanceY := Y-YY
}
Asd := DistanceY/DistanceX
Transform, Angle1, ATan, %Asd% 
Angle2 :=Angle1*180/3.14
Transform, Angle3, Cos,%Angle2%
Transform, Angle4, Sin,%Angle2% 
XXX := Angle3*50
YYY := Angle4*50
XXXX:= XX-XXX
YYYY:=YY-YYY
WinMove, Ringula,, %XXXX% , %YYYY%
GetKeyState, state, LButton, P
if state = U
break
}
Splashimage, Off
Click up
Return





I edited subject name.