Crosshair Toggle on Button press Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Kezraw
Posts: 3
Joined: 11 Aug 2016, 19:56

Crosshair Toggle on Button press

11 Aug 2016, 20:03

Hello, AHK community, I've been using an AHK crosshair overlay for some while now, and I find it to be near perfect, except for the one deficiency of not being able to turn the crosshair/drawn image off while (for example) pressing the right mouse button, and the crosshair showing immediately upon release of the RMB.
I tried my luck with the GetKeyState already, but I seem to have some major flaws in what I've tried, because it did absolutely nothing for me. Anyway, hoping for some help; below the existing 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, 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,chxt, %ScriptName%.ini, Crochair tol,chxt
	IniRead,chyt, %ScriptName%.ini, Crochair tol,chyt
	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
{
	chxt = 0
	chyt = 0
	IniWrite, %chxt%, %ScriptName%.ini , Crochair tol, chxt
	IniWrite, %chyt%, %ScriptName%.ini , Crochair tol, chyt
	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
}
;------------------------------------------


SetTimer, menu, 120
goto menu

PGDN::
{
	if vm = 1
	{
		vm = 0
		SetTimer, menu, Off
		ToolTip,,,,1
	}
	else if vm = 0
	{
		vm = 1
		SetTimer, menu, 120
		goto menu
	}
}
return

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




Home:: ;------------Show/Hide Crochair
{
	if chv = 0
	{
		if ft = 1
			gosub, showch
		else if ft =0
			gosub, drawch
		chv = 1
		SetTimer, tick, 200
	}
	else if chv = 1
	{
		Gui, Cancel
		SetTimer, tick, Off
		chv = 0
	}
}
return 
showch:
{
	if ft = 1
	{
		WinGetActiveTitle, wint
		WinGetPos, winx, winy, winw, winh, %wint%
		gosub, posch
		Gui Add, Picture, w%chimgw% h%chimgh% AltSubmit, %A_ScriptDir%\IMG\%chimg%
		Gui Color, FFFFFF
		Gui Show, NA x%chx% y%chy%
		Gui +AlwaysOnTop
		WinSet, TransColor, White, %A_ScriptName%
		Gui -Caption
		ft = 0
	}
}
return


posch:
{
    chx := winx + (winw /2) + chxt - chimgw
    chy := winy + (winh /2) + chyt - chimgh
}
return

drawch:
{
    GoSub, posch
	Gui, Show, NA x%chx% y%chy%
}
return

tick:
{
    IfWinActive, %wint%
    {
        WinGetPos, winx1, winy1, winw1, winh1, %wint%
		if winx1 <> winx or winy1 <> winy or winw1 <> winw or winh1 <> winh
		{
			WinGetPos, winx, winy, winw, winh, %wint%
			if chv = 1
				GoSub, drawch
		}
    }
	else
	{
		Gui, Cancel
	}
}
return

 ;-------------------------------Move/Adjust Crochair
{
^!+Up::
{
    chyt -= 1
    GoSub, drawch
    IniWrite, %chyt%, %ScriptName%.ini, Crochair tol, chyt
}
return

^!+Down::
{
    chyt += 1
    GoSub, drawch
    IniWrite, %chyt%, %ScriptName%.ini, Crochair tol, chyt
}
return

^!+Left::
{
    chxt -= 1
    GoSub, drawch
    IniWrite, %chxt%, %ScriptName%.ini, Crochair tol, chxt
}
return

^!+Right::
{
    chxt += 1
    GoSub, drawch
    IniWrite, %chxt%, %ScriptName%.ini, Crochair tol, chxt
}
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

NumpadSub::
{
	if chv = 1
	{
		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::
{
	if chv = 1
	{
		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

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 ;-------------------------------
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Crosshair Toggle on Button press

13 Aug 2016, 11:13

Hi bro,

I will work on it soon.

hold tight.
:wave: There is always more than one way to solve a problem. ;)
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Crosshair Toggle on Button press

13 Aug 2016, 11:48

Kezraw wrote:Hello, AHK community, I've been using an AHK crosshair overlay for some while now, and I find it to be near perfect, except for the one deficiency of not being able to turn the crosshair/drawn image off while (for example) pressing the right mouse button, and the crosshair showing immediately upon release of the RMB.
I tried my luck with the GetKeyState already, but I seem to have some major flaws in what I've tried, because it did absolutely nothing for me. Anyway, hoping for some help; below the existing code.
Add this code to the script. :terms:

Code: Select all

#if chv = 1

*~RButton:: ;------------Hide Crochair
Gui, Cancel
SetTimer, tick, Off
return

*~RButton Up:: ;------------Show Crochair
Sleep, 250
gosub, drawch
SetTimer, tick, 200
return

#if
:wave: There is always more than one way to solve a problem. ;)
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Crosshair Toggle on Button press  Topic is solved

13 Aug 2016, 12:02

and you asked me if you have new one, well I don't

you can go to "IMG" folder, those files are just pictures

Image

change them and keep the name, and remove ".jpg", :bravo: you got your newer Crosshair.
:wave: There is always more than one way to solve a problem. ;)
Kezraw
Posts: 3
Joined: 11 Aug 2016, 19:56

Re: Crosshair Toggle on Button press

13 Aug 2016, 12:06

YoucefHam wrote:
Kezraw wrote:Hello, AHK community, I've been using an AHK crosshair overlay for some while now, and I find it to be near perfect, except for the one deficiency of not being able to turn the crosshair/drawn image off while (for example) pressing the right mouse button, and the crosshair showing immediately upon release of the RMB.
I tried my luck with the GetKeyState already, but I seem to have some major flaws in what I've tried, because it did absolutely nothing for me. Anyway, hoping for some help; below the existing code.
Add this code to the script. :terms:

Code: Select all

#if chv = 1

*~RButton:: ;------------Hide Crochair
Gui, Cancel
SetTimer, tick, Off
return

*~RButton Up:: ;------------Show Crochair
Sleep, 250
gosub, drawch
SetTimer, tick, 200
return

#if
This works. Thank you so much :D :wave:
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

09 Jun 2021, 15:37

Does anyone have a download for everything mentioned here? I've scoured the internet in search of a cheap effective crosshair overlay that hides on right click.
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

09 Jun 2021, 15:47

I'm using
@YoucefHam script but I want to have the images show up.
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

09 Jun 2021, 15:51

WTF. The crosshair is running away from me.
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Crosshair Toggle on Button press

09 Jun 2021, 15:51

Denner Slabz wrote:
09 Jun 2021, 15:47
I'm using
@YoucefHam script but I want to have the images show up.
Hi,
what do you mean by showing up the images !!!
: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

09 Jun 2021, 15:54

YoucefHam wrote:
09 Jun 2021, 15:51
Denner Slabz wrote:
09 Jun 2021, 15:47
I'm using
@YoucefHam script but I want to have the images show up.
Hi,
what do you mean by showing up the images !!!
Nevermind, it works. But it looks to be very glitchy. Do you have a download for the latest version of your app? Thanks in advance!
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

09 Jun 2021, 15:55

Nevermind it is showing, but it is very glitchy. Do you have the latest version I can download?
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Crosshair Toggle on Button press

09 Jun 2021, 16:15

Denner Slabz wrote:
09 Jun 2021, 15:55
Nevermind it is showing, but it is very glitchy. Do you have the latest version I can download?
Here it is the last time I used it.

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%chimgh% 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

09 Jun 2021, 16:33

YoucefHam wrote:
09 Jun 2021, 16:15
Denner Slabz wrote:
09 Jun 2021, 15:55
Nevermind it is showing, but it is very glitchy. Do you have the latest version I can download?
Here it is the last time I used it.

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%chimgh% 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
}
Oh yes that is so much better. However when I press HOME to show the crosshair it says an error, either
image.png
image.png (17.03 KiB) Viewed 2578 times
or
image.png
image.png (17.9 KiB) Viewed 2578 times
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

09 Jun 2021, 16:34

Crosshair show/hide errors:

Invalid option.

The same variable cannot be used for more than one control.
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Crosshair Toggle on Button press

09 Jun 2021, 16:42

Try to delete "Crosshair.ini" then run
: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

09 Jun 2021, 17:01

YoucefHam wrote:
09 Jun 2021, 16:42
Try to delete "Crosshair.ini" then run
THANK YOU!

So do you know if I can put my own image into it?

Also the keybinds can be changed easily, right?

Also I am assuming if I put the code you mentioned earlier, it will hide the crosshair on right click?
Denner Slabz
Posts: 25
Joined: 26 Sep 2020, 01:48

Re: Crosshair Toggle on Button press

09 Jun 2021, 17:07

Oh no, there are some more problems.
image.png
image.png (10.57 KiB) Viewed 2563 times
These don't work for some reason.

Also I can't change the crosshair from the blue
image.png
image.png (643 Bytes) Viewed 2563 times
The IMG file is downloaded from an old version, that might be the issue?
Can I use a png file I downloaded also? If so, I don't know how to do that, the IMG files CH11 etc. are confusing.
image.png
image.png (6.53 KiB) Viewed 2560 times
Edit: I don't really need those keybinds to change the type etc. because I would just use my own PNG image for crosshair. But I don't know how to connect it to autohotkey.
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Crosshair Toggle on Button press

09 Jun 2021, 17:19

put your image file inside IMG folder the open "Crosshair.ini" and change "PictureFile=Your_File_Name.png"
: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

09 Jun 2021, 17:34

The image is distorted a little; it happens when I adjust the size to be smaller in the .ini file; is there any fix to that?

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 47 guests