Crosshair Toggle on Button press Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Crosshair Toggle on Button press

Post by YoucefHam » 09 Jun 2021, 17:51

use this code

Code: Select all

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Windows 7/8/8.1 32/64bit
; Author:         Youcef Hamdani 	<[email protected]>
;				  YOUCEFHam 		<www.mpgh.net>
; Script Function:
;    
;
{
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, ToolTip, Client
CoordMode, Menu, Screen
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen

;-------------Remove .ahk and .exe from filename to get name for INI file
ScriptName := A_ScriptName
StringReplace, ScriptName, ScriptName, .ahk,, All
StringReplace, ScriptName, ScriptName, .exe,, All
}

;---------------------------------------YOUCEFHam-----------------------------No Recoil/Rapid Fire
vm = 1
ft = 1
chv = 0

;--------------------Load the saved values.
IfExist %ScriptName%.ini
{
	IniRead,chx, %ScriptName%.ini, Crochair tol,chx
	IniRead,chy, %ScriptName%.ini, Crochair tol,chy
	IniRead,chp, %ScriptName%.ini, Crochair Picture, PictureNum
	IniRead,chcl, %ScriptName%.ini, Crochair Picture, Picturecolor
	IniRead,chc, %ScriptName%.ini, Crochair Picture, Picturecolorval
	IniRead,chimg, %ScriptName%.ini, Crochair Picture, PictureFile
	IniRead,chimgw, %ScriptName%.ini, Crochair Picture, PictureWidth
	IniRead,chimgh, %ScriptName%.ini, Crochair Picture, PictureHeight
}
;------------------------------------------

;--------------------Set the new values.
IfnotExist %ScriptName%.ini
{
	chx := Ceil(A_ScreenWidth / 2)
	chy := Ceil(A_ScreenHeight / 2)
	IniWrite, %chx%, %ScriptName%.ini , Crochair tol, chx
	IniWrite, %chy%, %ScriptName%.ini , Crochair tol, chy
	chp = 1
	chc = 1
	chcl = Blue
	IniWrite, %chp%, %ScriptName%.ini , Crochair Picture, PictureNum
	IniWrite, %chcl%, %ScriptName%.ini , Crochair Picture, Picturecolor
	IniWrite, %chc%, %ScriptName%.ini , Crochair Picture, Picturecolorval
	chimg = CH%chp%%chc%
	chimgw = 60
	chimgh = 60
	IniWrite, %chimg%, %ScriptName%.ini , Crochair Picture, PictureFile
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
}
;------------------------------------------

menu:
{
ToolTip,Crosshair Type:	%chp%`nCrosshair Color:	%chcl%`nCrosshair Size:	%chimgw%`n---------------------------------------------`nKey		Effect`nPageDown	Show/Hide Menu`nHome		Show/Hide Crosshair`nCtrl+/		Change Crosshair type`nCtrl+*		Change Crosshair color`nCtrl++		Increase Crosshair Size`nCtrl+-		Decrease Crosshair Size`nCtrl+Arows	Move Crosshair Position`nCtrl+Numpad 0	Move Crosshair`nEnd		Reload`nPause		Pause`nDelete		Exit`n---------------------------------------------`nCreated By 		      YoucefHam,0,0,1
}
return

MoveGui:
{
	PostMessage, 0xA1, 2,,, HYCrousshair
}
return

showch:
{
	if ft = 1
	{
		WinGetActiveTitle, wint
		WinGet, active_id, ProcessName, %wint%
		wint = ahk_exe %active_id%
		WinGetPos, winx, winy, winw, winh, %wint%
		Gui Add, Picture, w%chimgw% h-1 AltSubmit gMoveGui vChr, %A_ScriptDir%\IMG\%chimg%
		Gui Color, FFFFFF
		Gui -Caption -Border -Sysmenu +AlwaysOnTop +ToolWindow +LastFound
		Gui Show, NA x%chx% y%chy%, HYCrousshair
		if !AppsKey_D
		{
			WinSet, TransColor, White, HYCrousshair
			WinSet, ExStyle, +0x20, HYCrousshair
		}
		ft = 0
	}
}
return

drawch:
{
	Gui, Show, NA x%chx% y%chy%, HYCrousshair
	WinSet, TransColor, White, HYCrousshair
	WinSet, ExStyle, +0x20, HYCrousshair
}
return

tick:
{
    If (WinActive(wint) or ("HYCrousshair"))
    {
		if Gui_
			if chv = 1
			{
				Gui, Show, NA x%chx% y%chy%, HYCrousshair
				Gui_ = 0
			}
    }
	else
	{
		Gui, Hide
		Gui_ = 1
	}
}
return


Home:: ;------------Show/Hide Crochair
{
	if chv = 0
	{
		if ft = 1
			gosub, showch
		else if ft = 0
			gosub, drawch
		chv = 1
		SetTimer, tick, 500
		vm = 0
		ToolTip,,,,1
	}
	else if chv = 1
	{
		Gui, Cancel
		SetTimer, tick, Off
		chv = 0
	}
}
return 

PGDN::
{
if !chv
	if vm
	{
		vm = 0
		ToolTip,,,,1
	}
	else
	{
		vm = 1
		goto menu
	}
}
return

Pause::  ;-------------Pause the script.
	Suspend, toggle
return ;-------------------------------

End::  ;-------------Reload the script
{
	Gui, Destroy
	Reload
}
return ;-------------------------------

Delete::  ;-------------Exit the script.
{
	Gui, Destroy
	Sleep, 200
	ExitApp
}
return ;-------------------------------

#If WinActive(wint)

PGUP::
if (wint <> "")
{
	WinSet, AlwaysOnTop, Toggle, % Wint
	WinSet, AlwaysOnTop, on, HYCrousshair
}
return

;-------------------------------Move/Adjust Crochair
#if AppsKey_D and chv
{

*WheelDown::
{
	if WheelUp
		return
	chimgw -= 5
	if chimgw < 5
		chimgw = 5
	chimgh -= 5
	if chimgh < 5
		chimgh = 5
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
	WheelDown = 1
	Sleep, 250
	WheelDown = 0
}
return

*WheelUp::
{
	if WheelDown
		return
	chimgw += 2
	if chimgw > 200
		chimgw = 200
	chimgh += 2
	if chimgh > 200
		chimgh = 200
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
	WheelUp = 1
	Sleep, 250
	WheelUp = 0
}
return

*~LButton::
{
	KeyWait, LButton, U
	WinGetPos, chx, chy,,, HYCrousshair
	IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
	IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
}
return
}

;-------------------------------Move/Adjust Crochair
#if chv and !AppsKey_D
{

^Numpad0::
*$AppsKey::
{
	IfInString, A_ThisHotkey, Numpad0
		UsedKey := "Numpad0"
	else
		UsedKey := "AppsKey"
	AppsKey_D = 1
	SetTimer, tick, Off
	winset, transcolor, Off, HYCrousshair
	WinSet, ExStyle, -0x20, HYCrousshair
	KeyWait, % UsedKey, U
	WinActivate, % wint
	WinGetPos, chx, chy,,, HYCrousshair
	IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
	IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
	WinSet, TransColor, White, HYCrousshair
	WinSet, ExStyle, +0x20, HYCrousshair
	AppsKey_D = 0
	SetTimer, tick, 500
}
return

^Up::
{
	WinGetPos, chx, chy,,, HYCrousshair
	chy -= 1
	WinMove, HYCrousshair,, chx, chy
	IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
}
return

^Down::
{
	WinGetPos, chx, chy,,, HYCrousshair
    chy += 1
	WinMove, HYCrousshair,, chx, chy
    IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
}
return

^Left::
{
	WinGetPos, chx, chy,,, HYCrousshair
    chx -= 1
	WinMove, HYCrousshair,, chx, chy
    IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
}
return

^Right::
{
	WinGetPos, chx, chy,,, HYCrousshair
    chx += 1
	WinMove, HYCrousshair,, chx, chy
    IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
}
return

^NumpadSub::
{
	chimgw -= 1
	if chimgw < 5
		chimgw = 5
	chimgh -= 1
	if chimgh < 5
		chimgh = 5
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
}
return

^NumpadAdd::
{
	chimgw += 1
	if chimgw > 200
		chimgw = 200
	chimgh += 1
	if chimgh > 200
		chimgh = 200
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
}
return

^NumpadDiv::
{
	if chv = 1
	{
		if chp = 1
		{
			chp = 2
			chimg = CH%chp%%chc%
		}
		else if chp = 2
		{
			chp = 3
			chimg = CH%chp%%chc%
		}
		else if chp = 3
		{
			chp = 4
			chimg = CH%chp%%chc%
		}
		else if chp = 4
		{
			chp = 5
			chimg = CH%chp%%chc%
		}
		else if chp = 5
		{
			chp = 6
			chimg = CH%chp%%chc%
		}
		else if chp = 6
		{
			chp = 1
			chimg = CH%chp%%chc%
		}
		IniWrite, %chimg%, %ScriptName%.ini , Crochair Picture, PictureFile
		IniWrite, %chp%, %ScriptName%.ini , Crochair Picture, PictureNum
		Gui, Destroy
		ft = 1
		gosub, showch
	}
}
return

^NumpadMult::
{
	if chv = 1
	{
		if chc = 1
		{
			chc = 2
			chcl = Green
			chimg = CH%chp%%chc%
		}
		else if chc = 2
		{
			chc = 3
			chcl = Red
			chimg = CH%chp%%chc%
		}
		else if chc = 3
		{
			chc = 4
			chcl = Yellow
			chimg = CH%chp%%chc%
		}
		else if chc = 4
		{
			chc = 1
			chcl = Blue
			chimg = CH%chp%%chc%
		}
		IniWrite, %chimg%, %ScriptName%.ini , Crochair Picture, PictureFile
		IniWrite, %chcl%, %ScriptName%.ini , Crochair Picture, Picturecolor
		IniWrite, %chc%, %ScriptName%.ini , Crochair Picture, Picturecolorval
		Gui, Destroy
		ft = 1
		gosub, showch
	}
}
return
}
:wave: There is always more than one way to solve a problem. ;)
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

Post by Denner Slabz » 09 Jun 2021, 19:40

Hmmmm I got it to stop being distorted but I want to add glow/stroke onto my crosshair to help it be seen better; it seems like it glitches when there is any variation in color, so I can't do it. Any suggestions?
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

Post by Denner Slabz » 09 Jun 2021, 19:43

YoucefHam wrote:
09 Jun 2021, 17:51
use this code

Code: Select all

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Windows 7/8/8.1 32/64bit
; Author:         Youcef Hamdani 	<[email protected]>
;				  YOUCEFHam 		<www.mpgh.net>
; Script Function:
;    
;
{
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, ToolTip, Client
CoordMode, Menu, Screen
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen

;-------------Remove .ahk and .exe from filename to get name for INI file
ScriptName := A_ScriptName
StringReplace, ScriptName, ScriptName, .ahk,, All
StringReplace, ScriptName, ScriptName, .exe,, All
}

;---------------------------------------YOUCEFHam-----------------------------No Recoil/Rapid Fire
vm = 1
ft = 1
chv = 0

;--------------------Load the saved values.
IfExist %ScriptName%.ini
{
	IniRead,chx, %ScriptName%.ini, Crochair tol,chx
	IniRead,chy, %ScriptName%.ini, Crochair tol,chy
	IniRead,chp, %ScriptName%.ini, Crochair Picture, PictureNum
	IniRead,chcl, %ScriptName%.ini, Crochair Picture, Picturecolor
	IniRead,chc, %ScriptName%.ini, Crochair Picture, Picturecolorval
	IniRead,chimg, %ScriptName%.ini, Crochair Picture, PictureFile
	IniRead,chimgw, %ScriptName%.ini, Crochair Picture, PictureWidth
	IniRead,chimgh, %ScriptName%.ini, Crochair Picture, PictureHeight
}
;------------------------------------------

;--------------------Set the new values.
IfnotExist %ScriptName%.ini
{
	chx := Ceil(A_ScreenWidth / 2)
	chy := Ceil(A_ScreenHeight / 2)
	IniWrite, %chx%, %ScriptName%.ini , Crochair tol, chx
	IniWrite, %chy%, %ScriptName%.ini , Crochair tol, chy
	chp = 1
	chc = 1
	chcl = Blue
	IniWrite, %chp%, %ScriptName%.ini , Crochair Picture, PictureNum
	IniWrite, %chcl%, %ScriptName%.ini , Crochair Picture, Picturecolor
	IniWrite, %chc%, %ScriptName%.ini , Crochair Picture, Picturecolorval
	chimg = CH%chp%%chc%
	chimgw = 60
	chimgh = 60
	IniWrite, %chimg%, %ScriptName%.ini , Crochair Picture, PictureFile
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
}
;------------------------------------------

menu:
{
ToolTip,Crosshair Type:	%chp%`nCrosshair Color:	%chcl%`nCrosshair Size:	%chimgw%`n---------------------------------------------`nKey		Effect`nPageDown	Show/Hide Menu`nHome		Show/Hide Crosshair`nCtrl+/		Change Crosshair type`nCtrl+*		Change Crosshair color`nCtrl++		Increase Crosshair Size`nCtrl+-		Decrease Crosshair Size`nCtrl+Arows	Move Crosshair Position`nCtrl+Numpad 0	Move Crosshair`nEnd		Reload`nPause		Pause`nDelete		Exit`n---------------------------------------------`nCreated By 		      YoucefHam,0,0,1
}
return

MoveGui:
{
	PostMessage, 0xA1, 2,,, HYCrousshair
}
return

showch:
{
	if ft = 1
	{
		WinGetActiveTitle, wint
		WinGet, active_id, ProcessName, %wint%
		wint = ahk_exe %active_id%
		WinGetPos, winx, winy, winw, winh, %wint%
		Gui Add, Picture, w%chimgw% h-1 AltSubmit gMoveGui vChr, %A_ScriptDir%\IMG\%chimg%
		Gui Color, FFFFFF
		Gui -Caption -Border -Sysmenu +AlwaysOnTop +ToolWindow +LastFound
		Gui Show, NA x%chx% y%chy%, HYCrousshair
		if !AppsKey_D
		{
			WinSet, TransColor, White, HYCrousshair
			WinSet, ExStyle, +0x20, HYCrousshair
		}
		ft = 0
	}
}
return

drawch:
{
	Gui, Show, NA x%chx% y%chy%, HYCrousshair
	WinSet, TransColor, White, HYCrousshair
	WinSet, ExStyle, +0x20, HYCrousshair
}
return

tick:
{
    If (WinActive(wint) or ("HYCrousshair"))
    {
		if Gui_
			if chv = 1
			{
				Gui, Show, NA x%chx% y%chy%, HYCrousshair
				Gui_ = 0
			}
    }
	else
	{
		Gui, Hide
		Gui_ = 1
	}
}
return


Home:: ;------------Show/Hide Crochair
{
	if chv = 0
	{
		if ft = 1
			gosub, showch
		else if ft = 0
			gosub, drawch
		chv = 1
		SetTimer, tick, 500
		vm = 0
		ToolTip,,,,1
	}
	else if chv = 1
	{
		Gui, Cancel
		SetTimer, tick, Off
		chv = 0
	}
}
return 

PGDN::
{
if !chv
	if vm
	{
		vm = 0
		ToolTip,,,,1
	}
	else
	{
		vm = 1
		goto menu
	}
}
return

Pause::  ;-------------Pause the script.
	Suspend, toggle
return ;-------------------------------

End::  ;-------------Reload the script
{
	Gui, Destroy
	Reload
}
return ;-------------------------------

Delete::  ;-------------Exit the script.
{
	Gui, Destroy
	Sleep, 200
	ExitApp
}
return ;-------------------------------

#If WinActive(wint)

PGUP::
if (wint <> "")
{
	WinSet, AlwaysOnTop, Toggle, % Wint
	WinSet, AlwaysOnTop, on, HYCrousshair
}
return

;-------------------------------Move/Adjust Crochair
#if AppsKey_D and chv
{

*WheelDown::
{
	if WheelUp
		return
	chimgw -= 5
	if chimgw < 5
		chimgw = 5
	chimgh -= 5
	if chimgh < 5
		chimgh = 5
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
	WheelDown = 1
	Sleep, 250
	WheelDown = 0
}
return

*WheelUp::
{
	if WheelDown
		return
	chimgw += 2
	if chimgw > 200
		chimgw = 200
	chimgh += 2
	if chimgh > 200
		chimgh = 200
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
	WheelUp = 1
	Sleep, 250
	WheelUp = 0
}
return

*~LButton::
{
	KeyWait, LButton, U
	WinGetPos, chx, chy,,, HYCrousshair
	IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
	IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
}
return
}

;-------------------------------Move/Adjust Crochair
#if chv and !AppsKey_D
{

^Numpad0::
*$AppsKey::
{
	IfInString, A_ThisHotkey, Numpad0
		UsedKey := "Numpad0"
	else
		UsedKey := "AppsKey"
	AppsKey_D = 1
	SetTimer, tick, Off
	winset, transcolor, Off, HYCrousshair
	WinSet, ExStyle, -0x20, HYCrousshair
	KeyWait, % UsedKey, U
	WinActivate, % wint
	WinGetPos, chx, chy,,, HYCrousshair
	IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
	IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
	WinSet, TransColor, White, HYCrousshair
	WinSet, ExStyle, +0x20, HYCrousshair
	AppsKey_D = 0
	SetTimer, tick, 500
}
return

^Up::
{
	WinGetPos, chx, chy,,, HYCrousshair
	chy -= 1
	WinMove, HYCrousshair,, chx, chy
	IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
}
return

^Down::
{
	WinGetPos, chx, chy,,, HYCrousshair
    chy += 1
	WinMove, HYCrousshair,, chx, chy
    IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
}
return

^Left::
{
	WinGetPos, chx, chy,,, HYCrousshair
    chx -= 1
	WinMove, HYCrousshair,, chx, chy
    IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
}
return

^Right::
{
	WinGetPos, chx, chy,,, HYCrousshair
    chx += 1
	WinMove, HYCrousshair,, chx, chy
    IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
}
return

^NumpadSub::
{
	chimgw -= 1
	if chimgw < 5
		chimgw = 5
	chimgh -= 1
	if chimgh < 5
		chimgh = 5
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
}
return

^NumpadAdd::
{
	chimgw += 1
	if chimgw > 200
		chimgw = 200
	chimgh += 1
	if chimgh > 200
		chimgh = 200
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
}
return

^NumpadDiv::
{
	if chv = 1
	{
		if chp = 1
		{
			chp = 2
			chimg = CH%chp%%chc%
		}
		else if chp = 2
		{
			chp = 3
			chimg = CH%chp%%chc%
		}
		else if chp = 3
		{
			chp = 4
			chimg = CH%chp%%chc%
		}
		else if chp = 4
		{
			chp = 5
			chimg = CH%chp%%chc%
		}
		else if chp = 5
		{
			chp = 6
			chimg = CH%chp%%chc%
		}
		else if chp = 6
		{
			chp = 1
			chimg = CH%chp%%chc%
		}
		IniWrite, %chimg%, %ScriptName%.ini , Crochair Picture, PictureFile
		IniWrite, %chp%, %ScriptName%.ini , Crochair Picture, PictureNum
		Gui, Destroy
		ft = 1
		gosub, showch
	}
}
return

^NumpadMult::
{
	if chv = 1
	{
		if chc = 1
		{
			chc = 2
			chcl = Green
			chimg = CH%chp%%chc%
		}
		else if chc = 2
		{
			chc = 3
			chcl = Red
			chimg = CH%chp%%chc%
		}
		else if chc = 3
		{
			chc = 4
			chcl = Yellow
			chimg = CH%chp%%chc%
		}
		else if chc = 4
		{
			chc = 1
			chcl = Blue
			chimg = CH%chp%%chc%
		}
		IniWrite, %chimg%, %ScriptName%.ini , Crochair Picture, PictureFile
		IniWrite, %chcl%, %ScriptName%.ini , Crochair Picture, Picturecolor
		IniWrite, %chc%, %ScriptName%.ini , Crochair Picture, Picturecolorval
		Gui, Destroy
		ft = 1
		gosub, showch
	}
}
return
}
What did you change with that version? I got the distortion fixed without it, but now I am trying to add glow/stroke to this. The only crosshair that looks smooth now is a simple one.
image.png
image.png (9.03 KiB) Viewed 1365 times
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

Post by Denner Slabz » 09 Jun 2021, 20:19

Whoever wants to know I've been trying to find a crosshair system for a game I am playing that has right click aim down sights. YoucefHam the legend has made this script and I was able to make a crosshair system. The only downside is that glows and partially transparent images make it glitch, but it isn't a necessity.

Normal crosshair looks like this:
image.png
image.png (539 Bytes) Viewed 1363 times
Right click crosshair looks like this:
image.png
image.png (423 Bytes) Viewed 1363 times
Thank you YoucefHam for the help. I was able to make a hell of a nice crosshair system that can probably be used for any game with aim down sights for right click. If anyone wants the crosshair I made I will post here the 2 crosshairs as well as the presets needed for them.

NORMAL CROSSHAIR:
[Crochair tol]
chx=900
chy=484
[Crochair Picture]
PictureNum=1
Picturecolor=Blue
Picturecolorval=1
PictureFile=Crosshair6
PictureWidth=100
PictureHeight=100

INVERSE CROSSHAIR:
[Crochair tol]
chx=948
chy=532
[Crochair Picture]
PictureNum=1
Picturecolor=Blue
Picturecolorval=1
PictureFile=Inverse2x2dot
PictureWidth=4
PictureHeight=4
Last edited by Denner Slabz on 10 Jun 2021, 12:13, edited 2 times in total.
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

Post by Denner Slabz » 09 Jun 2021, 20:21

Normal crosshair: crosshair6.png (Remove .png)
Right click crosshair: 2x2.png (remove .png)
Attachments
2x2.png
2x2.png (84 Bytes) Viewed 1361 times
Crosshair6.png
Crosshair6.png (6.84 KiB) Viewed 1361 times
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

Post by Denner Slabz » 16 Jun 2021, 13:03

YoucefHam wrote:
09 Jun 2021, 17:51
use this code

Code: Select all

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Windows 7/8/8.1 32/64bit
; Author:         Youcef Hamdani 	<[email protected]>
;				  YOUCEFHam 		<www.mpgh.net>
; Script Function:
;    
;
{
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, ToolTip, Client
CoordMode, Menu, Screen
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen

;-------------Remove .ahk and .exe from filename to get name for INI file
ScriptName := A_ScriptName
StringReplace, ScriptName, ScriptName, .ahk,, All
StringReplace, ScriptName, ScriptName, .exe,, All
}

;---------------------------------------YOUCEFHam-----------------------------No Recoil/Rapid Fire
vm = 1
ft = 1
chv = 0

;--------------------Load the saved values.
IfExist %ScriptName%.ini
{
	IniRead,chx, %ScriptName%.ini, Crochair tol,chx
	IniRead,chy, %ScriptName%.ini, Crochair tol,chy
	IniRead,chp, %ScriptName%.ini, Crochair Picture, PictureNum
	IniRead,chcl, %ScriptName%.ini, Crochair Picture, Picturecolor
	IniRead,chc, %ScriptName%.ini, Crochair Picture, Picturecolorval
	IniRead,chimg, %ScriptName%.ini, Crochair Picture, PictureFile
	IniRead,chimgw, %ScriptName%.ini, Crochair Picture, PictureWidth
	IniRead,chimgh, %ScriptName%.ini, Crochair Picture, PictureHeight
}
;------------------------------------------

;--------------------Set the new values.
IfnotExist %ScriptName%.ini
{
	chx := Ceil(A_ScreenWidth / 2)
	chy := Ceil(A_ScreenHeight / 2)
	IniWrite, %chx%, %ScriptName%.ini , Crochair tol, chx
	IniWrite, %chy%, %ScriptName%.ini , Crochair tol, chy
	chp = 1
	chc = 1
	chcl = Blue
	IniWrite, %chp%, %ScriptName%.ini , Crochair Picture, PictureNum
	IniWrite, %chcl%, %ScriptName%.ini , Crochair Picture, Picturecolor
	IniWrite, %chc%, %ScriptName%.ini , Crochair Picture, Picturecolorval
	chimg = CH%chp%%chc%
	chimgw = 60
	chimgh = 60
	IniWrite, %chimg%, %ScriptName%.ini , Crochair Picture, PictureFile
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
}
;------------------------------------------

menu:
{
ToolTip,Crosshair Type:	%chp%`nCrosshair Color:	%chcl%`nCrosshair Size:	%chimgw%`n---------------------------------------------`nKey		Effect`nPageDown	Show/Hide Menu`nHome		Show/Hide Crosshair`nCtrl+/		Change Crosshair type`nCtrl+*		Change Crosshair color`nCtrl++		Increase Crosshair Size`nCtrl+-		Decrease Crosshair Size`nCtrl+Arows	Move Crosshair Position`nCtrl+Numpad 0	Move Crosshair`nEnd		Reload`nPause		Pause`nDelete		Exit`n---------------------------------------------`nCreated By 		      YoucefHam,0,0,1
}
return

MoveGui:
{
	PostMessage, 0xA1, 2,,, HYCrousshair
}
return

showch:
{
	if ft = 1
	{
		WinGetActiveTitle, wint
		WinGet, active_id, ProcessName, %wint%
		wint = ahk_exe %active_id%
		WinGetPos, winx, winy, winw, winh, %wint%
		Gui Add, Picture, w%chimgw% h-1 AltSubmit gMoveGui vChr, %A_ScriptDir%\IMG\%chimg%
		Gui Color, FFFFFF
		Gui -Caption -Border -Sysmenu +AlwaysOnTop +ToolWindow +LastFound
		Gui Show, NA x%chx% y%chy%, HYCrousshair
		if !AppsKey_D
		{
			WinSet, TransColor, White, HYCrousshair
			WinSet, ExStyle, +0x20, HYCrousshair
		}
		ft = 0
	}
}
return

drawch:
{
	Gui, Show, NA x%chx% y%chy%, HYCrousshair
	WinSet, TransColor, White, HYCrousshair
	WinSet, ExStyle, +0x20, HYCrousshair
}
return

tick:
{
    If (WinActive(wint) or ("HYCrousshair"))
    {
		if Gui_
			if chv = 1
			{
				Gui, Show, NA x%chx% y%chy%, HYCrousshair
				Gui_ = 0
			}
    }
	else
	{
		Gui, Hide
		Gui_ = 1
	}
}
return


Home:: ;------------Show/Hide Crochair
{
	if chv = 0
	{
		if ft = 1
			gosub, showch
		else if ft = 0
			gosub, drawch
		chv = 1
		SetTimer, tick, 500
		vm = 0
		ToolTip,,,,1
	}
	else if chv = 1
	{
		Gui, Cancel
		SetTimer, tick, Off
		chv = 0
	}
}
return 

PGDN::
{
if !chv
	if vm
	{
		vm = 0
		ToolTip,,,,1
	}
	else
	{
		vm = 1
		goto menu
	}
}
return

Pause::  ;-------------Pause the script.
	Suspend, toggle
return ;-------------------------------

End::  ;-------------Reload the script
{
	Gui, Destroy
	Reload
}
return ;-------------------------------

Delete::  ;-------------Exit the script.
{
	Gui, Destroy
	Sleep, 200
	ExitApp
}
return ;-------------------------------

#If WinActive(wint)

PGUP::
if (wint <> "")
{
	WinSet, AlwaysOnTop, Toggle, % Wint
	WinSet, AlwaysOnTop, on, HYCrousshair
}
return

;-------------------------------Move/Adjust Crochair
#if AppsKey_D and chv
{

*WheelDown::
{
	if WheelUp
		return
	chimgw -= 5
	if chimgw < 5
		chimgw = 5
	chimgh -= 5
	if chimgh < 5
		chimgh = 5
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
	WheelDown = 1
	Sleep, 250
	WheelDown = 0
}
return

*WheelUp::
{
	if WheelDown
		return
	chimgw += 2
	if chimgw > 200
		chimgw = 200
	chimgh += 2
	if chimgh > 200
		chimgh = 200
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
	WheelUp = 1
	Sleep, 250
	WheelUp = 0
}
return

*~LButton::
{
	KeyWait, LButton, U
	WinGetPos, chx, chy,,, HYCrousshair
	IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
	IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
}
return
}

;-------------------------------Move/Adjust Crochair
#if chv and !AppsKey_D
{

^Numpad0::
*$AppsKey::
{
	IfInString, A_ThisHotkey, Numpad0
		UsedKey := "Numpad0"
	else
		UsedKey := "AppsKey"
	AppsKey_D = 1
	SetTimer, tick, Off
	winset, transcolor, Off, HYCrousshair
	WinSet, ExStyle, -0x20, HYCrousshair
	KeyWait, % UsedKey, U
	WinActivate, % wint
	WinGetPos, chx, chy,,, HYCrousshair
	IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
	IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
	WinSet, TransColor, White, HYCrousshair
	WinSet, ExStyle, +0x20, HYCrousshair
	AppsKey_D = 0
	SetTimer, tick, 500
}
return

^Up::
{
	WinGetPos, chx, chy,,, HYCrousshair
	chy -= 1
	WinMove, HYCrousshair,, chx, chy
	IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
}
return

^Down::
{
	WinGetPos, chx, chy,,, HYCrousshair
    chy += 1
	WinMove, HYCrousshair,, chx, chy
    IniWrite, %chy%, %ScriptName%.ini, Crochair tol, chy
}
return

^Left::
{
	WinGetPos, chx, chy,,, HYCrousshair
    chx -= 1
	WinMove, HYCrousshair,, chx, chy
    IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
}
return

^Right::
{
	WinGetPos, chx, chy,,, HYCrousshair
    chx += 1
	WinMove, HYCrousshair,, chx, chy
    IniWrite, %chx%, %ScriptName%.ini, Crochair tol, chx
}
return

^NumpadSub::
{
	chimgw -= 1
	if chimgw < 5
		chimgw = 5
	chimgh -= 1
	if chimgh < 5
		chimgh = 5
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
}
return

^NumpadAdd::
{
	chimgw += 1
	if chimgw > 200
		chimgw = 200
	chimgh += 1
	if chimgh > 200
		chimgh = 200
	IniWrite, %chimgw%, %ScriptName%.ini , Crochair Picture, PictureWidth
	IniWrite, %chimgh%, %ScriptName%.ini , Crochair Picture, PictureHeight
	Gui, Destroy
	ft = 1
	gosub, showch
}
return

^NumpadDiv::
{
	if chv = 1
	{
		if chp = 1
		{
			chp = 2
			chimg = CH%chp%%chc%
		}
		else if chp = 2
		{
			chp = 3
			chimg = CH%chp%%chc%
		}
		else if chp = 3
		{
			chp = 4
			chimg = CH%chp%%chc%
		}
		else if chp = 4
		{
			chp = 5
			chimg = CH%chp%%chc%
		}
		else if chp = 5
		{
			chp = 6
			chimg = CH%chp%%chc%
		}
		else if chp = 6
		{
			chp = 1
			chimg = CH%chp%%chc%
		}
		IniWrite, %chimg%, %ScriptName%.ini , Crochair Picture, PictureFile
		IniWrite, %chp%, %ScriptName%.ini , Crochair Picture, PictureNum
		Gui, Destroy
		ft = 1
		gosub, showch
	}
}
return

^NumpadMult::
{
	if chv = 1
	{
		if chc = 1
		{
			chc = 2
			chcl = Green
			chimg = CH%chp%%chc%
		}
		else if chc = 2
		{
			chc = 3
			chcl = Red
			chimg = CH%chp%%chc%
		}
		else if chc = 3
		{
			chc = 4
			chcl = Yellow
			chimg = CH%chp%%chc%
		}
		else if chc = 4
		{
			chc = 1
			chcl = Blue
			chimg = CH%chp%%chc%
		}
		IniWrite, %chimg%, %ScriptName%.ini , Crochair Picture, PictureFile
		IniWrite, %chcl%, %ScriptName%.ini , Crochair Picture, Picturecolor
		IniWrite, %chc%, %ScriptName%.ini , Crochair Picture, Picturecolorval
		Gui, Destroy
		ft = 1
		gosub, showch
	}
}
return
}
Youcef, I'm having trouble centering the custom crosshairs I've made, it's always one pixel to the left/right etc.. And right now when I move the crosshair using CTRL and arrows it goes further than one pixel. Is this possibly because my display is 1920x1080 or is there anything else that has to do with it?

I want the crosshair to be perfectly centered, I think it is possible, my crosshair gap is 4 pixels so I think it's possible for it to center.
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

Post by Denner Slabz » 16 Jun 2021, 13:06

Example image:
image.png
image.png (24.65 KiB) Viewed 1311 times
Last edited by Denner Slabz on 16 Jun 2021, 13:08, edited 1 time in total.
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Crosshair Toggle on Button press

Post by YoucefHam » 16 Jun 2021, 21:38

Denner Slabz wrote:
16 Jun 2021, 13:03
Youcef, I'm having trouble centering the custom crosshairs I've made, it's always one pixel to the left/right etc.. And right now when I move the crosshair using CTRL and arrows it goes further than one pixel. Is this possibly because my display is 1920x1080 or is there anything else that has to do with it?

I want the crosshair to be perfectly centered, I think it is possible, my crosshair gap is 4 pixels so I think it's possible for it to center.
try using this
Image
:wave: There is always more than one way to solve a problem. ;)
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

Post by Denner Slabz » 22 Jun 2021, 00:07

All good! :superhappy: :superhappy: :superhappy: :superhappy: :superhappy: :superhappy:
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

Post by Denner Slabz » 12 Jul 2021, 17:00

Hey, I'm back. I've been loving this crosshair and it has been perfect on all my games. However I don't have a high-end PC and I have to use borderless mode which affects my FPS.

I'm wondering if there is a way to render the crosshair even when the game is fullscreen?
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

Post by Denner Slabz » 20 Mar 2022, 22:16

Helllo youcef: I am getitng this error again with crosshair:
image.png
image.png (895 Bytes) Viewed 865 times
^ There are white spots around it
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

Post by Denner Slabz » 21 Mar 2022, 17:55

YoucefHam wrote:
16 Jun 2021, 21:38
Denner Slabz wrote:
16 Jun 2021, 13:03
Youcef, I'm having trouble centering the custom crosshairs I've made, it's always one pixel to the left/right etc.. And right now when I move the crosshair using CTRL and arrows it goes further than one pixel. Is this possibly because my display is 1920x1080 or is there anything else that has to do with it?

I want the crosshair to be perfectly centered, I think it is possible, my crosshair gap is 4 pixels so I think it's possible for it to center.
try using this
Image
Can you maybe do a script that makes it so that i don't get this white area?
Post Reply

Return to “Gaming Help (v1)”