Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

generate a line on screen


  • Please log in to reply
11 replies to this topic
evan
  • Guests
  • Last active:
  • Joined: --
i want to generate a line on screen from point x500,y500 to my mouse cursor position.
which functions should i look into?
the line can be fixed length also.

something similar to the below video example, but i want to display only the line, so that i can use it on top of other programs
thank you
Posted Image

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Aah, you've hit upon one of AHK very few weak points... Graphics.

I recall a previous post where an oddly shaped progress bar was used as a makeshift graphical appendage.

Try playing around with the [Progress] command and try to make a progress bar 1 pixel wide and maybe 30 pixels tall.

evan
  • Guests
  • Last active:
  • Joined: --
this is what i intended to use on (Game Aimer):

Posted Image

(i use paint, and winset transparent the white section, doesnt work because i need to constantly hold left click =_=)

so if i try to use the method u mention, probably the computer will go crazy reloading those points

evan
  • Guests
  • Last active:
  • Joined: --
how could i forget this:
Thank you for the idea!

and also someone mention about overlay or hook a draw call to me earlier, but havent found any programs does that yet

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
you may be able to adapt this: <!-- m -->http://www.autohotke...pic.php?t=19300<!-- m -->

Rhys
  • Members
  • 761 posts
  • Last active: Aug 09 2013 04:53 PM
  • Joined: 17 Apr 2007
Is this what you're looking for? Esc will exit - It is a bit flickery on my system (you can try updating the settimer line) but it works.

Credit to AHKLerner:

CoordMode, Mouse, Screen

Black    = 000000
Green    = 008000
Silver    = C0C0C0
Lime       = 00FF00
Gray       = 808080
Olive       = 808000
White    = FFFFFF
Yellow    = FFFF00
Maroon    = 800000
Navy    = 000080
Red       = FF0000
Blue       = 0000FF
Purple    = 800080
Teal       = 008080
Fuchsia    = FF00FF
Aqua    = 00FFFF

Gui, 1:+LastFound +AlwaysOnTop +ToolWindow
Gui, 1:-Caption
Gui, 1:Color, 008080
WinSet, TransColor, 008080
GuiHwnd := WinExist()
Gui, 1:Show
Gui, 1:Maximize
SetTimer, DrawLine, 50
return

DrawLine:
MouseGetPos, M_x, M_y
If (M_x != Old_M_x or M_y != Old_M_y)
   WinSet, Redraw,, ahk_id %GuiHwnd%
Canvas_DrawLine(GuihWnd, 500, 500, M_x, M_y, 2, Red)

Old_M_x := M_x
Old_M_y := M_y
return


esc::exitapp
Canvas_DrawLine(hWnd, p_x1, p_y1, p_x2, p_y2, p_w, p_color) ; r,angle,width,color)
   {
   p_x1 -= 1, p_y1 -= 1, p_x2 -= 1, p_y2 -= 1
   hDC := DllCall("GetDC", UInt, hWnd)
   hCurrPen := DllCall("CreatePen", UInt, 0, UInt, p_w, UInt, Convert_BGR(p_color))
   DllCall("SelectObject", UInt,hdc, UInt,hCurrPen)
   DllCall("gdi32.dll\MoveToEx", UInt, hdc, Uint,p_x1, Uint, p_y1, Uint, 0 )
   DllCall("gdi32.dll\LineTo", UInt, hdc, Uint, p_x2, Uint, p_y2 )
   DllCall("ReleaseDC", UInt, 0, UInt, hDC)  ; Clean-up.
   DllCall("DeleteObject", UInt,hCurrPen)
   }

   
Convert_BGR(RGB)
   {
   StringLeft, r, RGB, 2
   StringMid, g, RGB, 3, 2
   StringRight, b, RGB, 2
   Return, "0x" . b . g . r
   }


evan
  • Guests
  • Last active:
  • Joined: --
[email protected] code, but too slow refresh rate for me.
[email protected] exactly what i am looking for, i am surprise ahk can do this when everyone tell me to just use another language.

thank you

evan
  • Guests
  • Last active:
  • Joined: --
thanks guys, tested in the game.
it works exactly what i want.
but the disappointing thing is those codes are out of my knowledge
i dont understand at all how he generates
i think i need to start practicing dllcall, it seems can do a lot of things

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
DllCAll can do anything. It's just a direct call to anything you can do in MSDN.

evan
  • Guests
  • Last active:
  • Joined: --
using the above script, i encounter another problem.
i always click on the line when its around 270-330degree
which steals focus from my game and make the fps really lag

i have an idea but dont know how to implant inside with dllcall codes
i want a 3x3 "00808F" circle or square region generate right on the mouse position "M_x, M_y", so with the script, it will transparent it, and i can never click the line by accident

please teach me, thank you

evanxxxm
  • Members
  • 10 posts
  • Last active: Jan 05 2013 12:22 PM
  • Joined: 14 Jun 2007
got it, thank you everyone

Sean wrote an example of drawing red dot with dllcall in another post
hRgn := DllCall( "CreateEllipticRgn", Int,485, Int,385, Int,505, Int,405 )
hBr  := DllCall( "CreateSolidBrush", UInt, 0x0000FF )
hDC  := DllCall( "GetDC", UInt,0 )
DllCall( "FillRgn", UInt,hDC, UInt,hRgn, UInt,hBr ) 
DllCall("ReleaseDC", "uint", 0, "uint", hDC)
DllCall("DeleteObject", UInt,hBr)
Sleep 1000
DllCall("RedrawWindow", "Uint", 0, "Uint", 0, "Uint", hRgn, "Uint", 0x81)
DllCall("DeleteObject", UInt,hRgn)

but now i have problem make it follow the mouse cursor...
anyone can point me which number in that code is X,Y location?
(i tried to do WinMove, ahk_id %??%,,100,100, but seems none of the var is correct for the ?? part..)

and also, i tried to learn what those dllcall does. i found out that without
DllCall("ReleaseDC", "uint", 0, "uint", hDC)
DllCall("DeleteObject", UInt,hBr)
the script still works perfectly. what exactly does that do?

evan
  • Guests
  • Last active:
  • Joined: --
finally, i got it fix
i added:
Blank = 008080
&
Canvas_DrawLine(GuihWnd, M_x, M_y, M_x, M_y, 30, Blank)
right below
Canvas_DrawLine(GuihWnd, 500, 500, M_x, M_y, 2, Red)

CoordMode, Mouse, Screen
Blank = 008080
Black    = 000000
Green    = 008000
Silver    = C0C0C0
Lime       = 00FF00
Gray       = 808080
Olive       = 808000
White    = FFFFFF
Yellow    = FFFF00
Maroon    = 800000
Navy    = 000080
Red       = FF0000
Blue       = 0000FF
Purple    = 800080
Teal       = 008080
Fuchsia    = FF00FF
Aqua    = 00FFFF

Gui, 1:+LastFound +AlwaysOnTop +ToolWindow
Gui, 1:-Caption
Gui, 1:Color, 008080
WinSet, TransColor, 008080
GuiHwnd := WinExist()
Gui, 1:Show
Gui, 1:Maximize
SetTimer, DrawLine, 50
return

DrawLine:
MouseGetPos, M_x, M_y
If (M_x != Old_M_x or M_y != Old_M_y)
   WinSet, Redraw,, ahk_id %GuiHwnd%
Canvas_DrawLine(GuihWnd, 500, 500, M_x, M_y, 2, Red)
Canvas_DrawLine(GuihWnd, M_x, M_y, M_x, M_y, 30, Blank)

Old_M_x := M_x
Old_M_y := M_y
return


esc::exitapp
Canvas_DrawLine(hWnd, p_x1, p_y1, p_x2, p_y2, p_w, p_color) ; r,angle,width,color)
   {
   p_x1 -= 1, p_y1 -= 1, p_x2 -= 1, p_y2 -= 1
   hDC := DllCall("GetDC", UInt, hWnd)
   hCurrPen := DllCall("CreatePen", UInt, 0, UInt, p_w, UInt, Convert_BGR(p_color))
   DllCall("SelectObject", UInt,hdc, UInt,hCurrPen)
   DllCall("gdi32.dll\MoveToEx", UInt, hdc, Uint,p_x1, Uint, p_y1, Uint, 0 )
   DllCall("gdi32.dll\LineTo", UInt, hdc, Uint, p_x2, Uint, p_y2 )
   DllCall("ReleaseDC", UInt, 0, UInt, hDC)  ; Clean-up.
   DllCall("DeleteObject", UInt,hCurrPen)
   }

   
Convert_BGR(RGB)
   {
   StringLeft, r, RGB, 2
   StringMid, g, RGB, 3, 2
   StringRight, b, RGB, 2
   Return, "0x" . b . g . r
   }