Making Opaque Circle around mouse

Ask gaming related questions
luckyluk3
Posts: 2
Joined: 28 Mar 2017, 22:25

Making Opaque Circle around mouse

28 Mar 2017, 22:35

Hi All

I'm trying to make multiple opaque circle centred on my mouse pointer so I can train myself for better aiming.
But the picture itself must be unobtrusive and does not effect (or pop up) the whole game itself.
I want to have the option to turn it on and off within a key push

anybody can help me where to start?
User avatar
Spawnova
Posts: 339
Joined: 08 Jul 2015, 00:12
Contact:

Re: Making Opaque Circle around mouse

29 Mar 2017, 04:15

I've written a quick script for you, however it uses the gdip.ahk library so you will need to download that first and save it to gdip.ahk in the same directory

here's a url for the library - http://www.autohotkey.net/~tic/Gdip.ahk

Once you have both gdip.ahk and this script in the same place, run this script and press F1 to toggle on and off the circle

Code: Select all

#include gdip.ahk ;download gdip.ahk at http://www.autohotkey.net/~tic/Gdip.ahk save it in the same directory as this script as gdip.ahk
coordmode,mouse,screen
radius := 100
radiusHalf := radius / 2
toggle := 0 ;off default
Gui,-Caption +E0x80000 +alwaysontop +toolwindow +E0x20 ;e0x20 = gui can be clicked through
gui,show,NA,MouseCircleGui
hwnd := WinExist("MouseCircleGui")

Gdip_Startup()
hbm := CreateDIBSection(radius,radius)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHdc(hdc)
circleBrush := Gdip_BrushCreateSolid(0x60FFFF00)  ;0x (transparency=20) (red=FF) (green=FF) (blue=FF)
return

f9::reload
f8::exitapp

f1::
toggle := !toggle ;inverts toggle state
if (toggle) {
	Gdip_FillEllipse(G,circleBrush,0,0,radius,radius)
	settimer,update,10
} else {
	settimer,update,off
	Gdip_GraphicsClear(G) ;clear the circle
	UpdateLayeredWindow(hwnd, hdc, mouse_x-radiusHalf, mouse_y-radiusHalf, radius, radius) ;update
}
return

update:
mousegetpos,mouse_x,mouse_y
UpdateLayeredWindow(hwnd, hdc, mouse_x-radiusHalf, mouse_y-radiusHalf, radius, radius)
return
luckyluk3
Posts: 2
Joined: 28 Mar 2017, 22:25

Re: Making Opaque Circle around mouse

29 Mar 2017, 12:27

Spawnova wrote:I've written a quick script for you, however it uses the gdip.ahk library so you will need to download that first and save it to gdip.ahk in the same directory

here's a url for the library - http://www.autohotkey.net/~tic/Gdip.ahk

Once you have both gdip.ahk and this script in the same place, run this script and press F1 to toggle on and off the circle

Code: Select all

#include gdip.ahk ;download gdip.ahk at http://www.autohotkey.net/~tic/Gdip.ahk save it in the same directory as this script as gdip.ahk
coordmode,mouse,screen
radius := 100
radiusHalf := radius / 2
toggle := 0 ;off default
Gui,-Caption +E0x80000 +alwaysontop +toolwindow +E0x20 ;e0x20 = gui can be clicked through
gui,show,NA,MouseCircleGui
hwnd := WinExist("MouseCircleGui")

Gdip_Startup()
hbm := CreateDIBSection(radius,radius)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHdc(hdc)
circleBrush := Gdip_BrushCreateSolid(0x60FFFF00)  ;0x (transparency=20) (red=FF) (green=FF) (blue=FF)
return

f9::reload
f8::exitapp

f1::
toggle := !toggle ;inverts toggle state
if (toggle) {
	Gdip_FillEllipse(G,circleBrush,0,0,radius,radius)
	settimer,update,10
} else {
	settimer,update,off
	Gdip_GraphicsClear(G) ;clear the circle
	UpdateLayeredWindow(hwnd, hdc, mouse_x-radiusHalf, mouse_y-radiusHalf, radius, radius) ;update
}
return

update:
mousegetpos,mouse_x,mouse_y
UpdateLayeredWindow(hwnd, hdc, mouse_x-radiusHalf, mouse_y-radiusHalf, radius, radius)
return
Hmm, I've tried your code, it doesnt seem to do anything.
I put the gdip on the same Dir as the script.
Is there anything i did wrong?
User avatar
Spawnova
Posts: 339
Joined: 08 Jul 2015, 00:12
Contact:

Re: Making Opaque Circle around mouse

29 Mar 2017, 22:18

hmm, well if you aren't getting an error when you run the script then everything should be in order. Make sure you press F1 to toggle it on/off and try to run as administrator also make sure your ahk is up to date (i am on v1.1.25.01 unicode 32 bit)

If none of that helps I'm not sure what else it could be, perhaps someone else might be more informed
John
Posts: 77
Joined: 10 Apr 2014, 08:59

Re: Making Opaque Circle around mouse

31 Mar 2017, 04:28

Here's one way to do it without gdip and instead setting the shape of the gui to a list of points/a polygon,

Code: Select all

setwindelay,-1
coordmode,mouse,screen
radius := 50
gui 1: +AlwaysOnTop -caption
Gui 1: color, FF0000
gui 1: show, % "x0 y0 w" a_screenwidth " h" a_screenheight, backdrop1
WinSet, ExStyle, +0x20, backdrop1 ;let's make the gui click throughable
winset,trans,50,backdrop1 ;transparency
loop {
	mousegetpos,mx,my
	newRegion := midpointAlgo(mx,my,radius) ;generating the "x-y" points of the circle
	winset,region, % newRegion,backdrop1 ;setting the shape of the gui to the points
}
return

rshift::
exitapp

midpointAlgo(x0, y0, radius) {
    x := radius
    y := 0
    err := 0
    oct := array()
    while (x >= y) {
		oct[1] .= x0 + x "-" y0 + y " "
		oct[2] .= x0 + y "-" y0 + x " "
		oct[3] .= x0 - y "-" y0 + x " "
		oct[4] .= x0 - x "-" y0 + y " "
		oct[5] .= x0 - x "-" y0 - y " "
		oct[6] .= x0 - y "-" y0 - x " "
		oct[7] .= x0 + y "-" y0 - x " "
		oct[8] .= x0 + x "-" y0 - y " "
		if (err <= 0) {
			y += 1
			err += 2*y + 1
		}
		if (err > 0) {
			x -= 1
			err -= 2*x + 1
		}
    }
	return % oct[1] oct[2] oct[3] oct[4] oct[5] oct[6] oct[7] oct[8] 
}
You can grab rest of the behavior logics from spawnova's script
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Making Opaque Circle around mouse

31 Mar 2017, 08:57

Thank you John for the code and the inspiration.

I have taken the idea of using WinSet, Region and applied it to an ellipse.

Code: Select all

#NoEnv
#SingleInstance, Force
#MaxThreadsPerHotkey, 2
CoordMode, Mouse, Screen

    Diameter := 2 * (Radius := 50)
    Gui, +AlwaysOnTop -Caption +LastFound +Owner E0x20
    Gui, Color, Yellow
    Gui, Show, Hide x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%
    WinSet, Transparent, 64

Return



;-------------------------------------------------------------------------------
F11:: ; hotkey to toggle on/off
;-------------------------------------------------------------------------------
    Gui, % (Toggle := ! Toggle) ? "Show" : "Hide", NA
    Gui, +LastFound ; for WinSet
    While Toggle {
        MouseGetPos, x, y
        x -= Radius, y -= Radius
        WinSet, Region, E %x%-%y% w%Diameter% h%Diameter%
    }

Return

Return to “Gaming”

Who is online

Users browsing this forum: ObjectiveSuspect and 27 guests