GUI Crosshair, to shown on game window only

Ask gaming related questions (AHK v1.1 and older)
rainrain
Posts: 45
Joined: 20 Jan 2022, 00:17

GUI Crosshair, to shown on game window only

Post by rainrain » 06 Oct 2022, 21:24

Hi, I needed my crosshair to be shown only on window game but not else where
also am I able to set the crosshair to adjust automatically based on window size?

Code: Select all

f2::
;Crosshair monRight Larger=Left/monBottom Larger=Up
toggle := !toggle
if toggle {
diam = 27
Gui -Caption +AlwaysOnTop +Owner  +Disabled -SysMenu
Gui margin,0,0
Gui add, ListView,	w%diam% h%diam%	-Hdr -E0x200 BackgroundYellow
SysGet, mon, Monitor
Gui show, % "x" monRight//3.189-(diam//2) " y" monBottom//2.186-(diam//2)
WinSet, Region, 9-0 10-5 9-5 8-6 7-6 6-7 5-8 5-9 4-10 4-11 0-10 0-16 4-15 4-16 5-17 5-18 6-19 7-20 8-20 9-21 10-21 9-26 15-26 14-21 15-21 16-20 17-20 18-19 19-18 19-17 20-16 20-15 24-16 24-10 20-11 20-10 19-9 19-8 18-7 17-6 16-6 15-5 14-5 15-0 9-0 12-9 10-5 9-5 8-6 7-6 6-7 5-8 5-9 4-10 4-11 8-13 4-15 4-16 5-17 5-18 6-19 7-20 8-20 9-21 10-21 12-17 14-21 15-21 16-20 17-20 18-19 19-18 19-17 20-16 20-15 16-13 20-11 20-10 19-9 19-8 18-7 17-6 16-6 15-5 14-5 12-9, A
}
else
{
    Gui, destroy
}
return

Lepes
Posts: 141
Joined: 06 May 2021, 07:32
Location: Spain

Re: GUI Crosshair, to shown on game window only

Post by Lepes » 07 Oct 2022, 00:36

maybe this help

Code: Select all

; Source: https://www.autohotkey.com/boards/viewtopic.php?f=18&t=109179&sid=3ed11ed273dfd9d5a8b4861f7f92643b

#IfWinActive, ahk_exe notepad.exe   ; f2 and ESC only active when notepad.exe is focused
f2::
  ;Crosshair monRight Larger=Left/monBottom Larger=Up
  toggle := !toggle
  if toggle {
    ; window size
    wingetpos, x,y,w,h, ahk_exe notepad.exe 
    diam := 27
    cx := w / 2 + x - diam / 2  ; centerX  keeps in mind diam window size
    
    titleBarHeight := 30
    ; cross should be just below game title bar, 
    ;cy := y + titleBarHeight ; activate this line to test if the window is just below game title bar.
    ; maybe your windows uses a different title bar height, increase 30 or 
    ; decrease it until cross window is setup properly
    
    
    cy := (h - titleBarHeight) / 2 + y - diam / 2 + titleBarHeight 
    ; centerY  keeps in mind diam window size
    
    Gui -Caption +AlwaysOnTop +Owner  +Disabled -SysMenu
    Gui margin,0,0
    Gui add, ListView,	w%diam% h%diam%	-Hdr -E0x200 BackgroundRed
    ;SysGet, mon, Monitor
    ; Since the game is a window, I don't think we need monitor settings
    ; I just set diam window position centered on game window
    tooltip, % "cx " cx "  cy " cy "`n w" w " h" h ; show CenterX and CenterY
    Gui show, % " x" cx " y" cy
    ;Gui show, % "x" monRight//3.189-(diam//2) " y" monBottom//2.186-(diam//2)

    WinSet, Region, 9-0 10-5 9-5 8-6 7-6 6-7 5-8 5-9 4-10 4-11 0-10 0-16 4-15 4-16 5-17 5-18 6-19 7-20 8-20 9-21 10-21 9-26 15-26 14-21 15-21 16-20 17-20 18-19 19-18 19-17 20-16 20-15 24-16 24-10 20-11 20-10 19-9 19-8 18-7 17-6 16-6 15-5 14-5 15-0 9-0 12-9 10-5 9-5 8-6 7-6 6-7 5-8 5-9 4-10 4-11 8-13 4-15 4-16 5-17 5-18 6-19 7-20 8-20 9-21 10-21 12-17 14-21 15-21 16-20 17-20 18-19 19-18 19-17 20-16 20-15 16-13 20-11 20-10 19-9 19-8 18-7 17-6 16-6 15-5 14-5 12-9, A
    WinActivate, ahk_exe notepad.exe  ; activate notepad.exe
  }  else   {
      Gui, destroy
      tooltip,  ; cancel tooltip
  }
  return

Esc:: ExitApp  ; closing while debugging.

#if

Post Reply

Return to “Gaming Help (v1)”