Zoom Function for FPS (Scripts Provided)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Monomoy
Posts: 34
Joined: 27 Aug 2019, 11:11

Zoom Function for FPS (Scripts Provided)

27 Aug 2019, 11:29

If you would like to, contact me on Discord: Monomoy#8291

I'm having difficulty posting youtube video on the forum without the link breaking
___________________________________________________________________

I'm playing on 1360x768
I want the ability to toggle zoom in on the center of the screen (centerpoint for my resolution is 680 384)(not sure how large the magnified window needs to be)
This will allow the player to zoom in without aiming down the sights

It is useful because aiming down the sights will cause some objects to render in at distance (grass, bushes, trees)
Also useful because some factions are ironsight only and do not have scopes, so this will allow ironsight classes to be competitive against scopes at range
Additionally, some kits are not provided binoculars

I've searched the internet for quite awhile and found two AHK scripts that are nearly functional
https://www.autohotkey.com/boards/viewtopic.php?t=29270

In addition to this relevant thread (Screen Magnifier V2)
https://www.autohotkey.com/boards/viewtopic.php?t=29270



The problems that I am having now:

The magnifier focus is following the mouse cursor when I just want it to lock on the middle of the screen coordinates then draw a viewing box 400 pixels large

The magnified window overlapping, is there a way to have the magnifier window be transparent to itself?
b0ff77c616cc5a96782199addd8e9347.png
b0ff77c616cc5a96782199addd8e9347.png (519.4 KiB) Viewed 6806 times



Here are some examples of the effect this would have in a FPS game
EsRRZbh.png
EsRRZbh.png (351.98 KiB) Viewed 6810 times
KtZTC0v.png
KtZTC0v.png (1.76 MiB) Viewed 6810 times
[ youtube ] https :// www.youtube.com /watch?v=7k6SitNNxnc[ / youtube ] Broken Link for safety

__________________________________________________________________________________________________________________________________________

These are the two scripts I have found by googling online and have attempted to make small edits to both already

*
Script in Progress:

Code: Select all

#Persistent
#NoEnv
Menu,Tray,NoStandard
OnExit handle_exit

State=0

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=000, yy:= 00, ww:=400, hh:=400

Alt:: ;hotkey here

key_to_scope:
State:=!State
send {Ctrl up}
send {Ctrl down}
send {Ctrl up}
If state
{
Gui,  +AlwaysOnTop  +E0x20 -Caption +Owner +Resize -ToolWindow
Gui, Show, NoActivate w300 h220 x0 y0 , PrintScreen
zoom:=1
antialize:=1
delay:=1
WinGet PrintScreenID, id  ,PrintScreen
WinSet Transparent, 254, PrintScreen
WinGet, PrintSourceID, id
hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )
hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)
hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
Gosub, Repaint
return
Repaint:
CoordMode, Mouse, Screen
MouseGetPos, start_x, start_y
Gui, Submit, NoHide
GuiControl,, delay2 , delay %delay% ms
WinGetPos, wx, wy, ww, wh , PrintScreen
wh2 := wh
DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )
DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,0, Int,ww, Int,wh
, UInt,hdd_frame, Int
, start_x-(ww / 2 / zoom)
, Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020)
if follow = 1
WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2
SetTimer, Repaint , %delay%
Return
GuiClose:
handle_exit:
DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp xxxxx
}
Else
Gui Destroy
Return

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Screen Magnifier by Holomind

Code: Select all

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=000, yy:= 00, ww:=400, hh:=400

;ScreenMagnifier from holomind 
;https://autohotkey.com/board/topic/10660-screenmagnifier/
OnExit handle_exit

  Gui,  +AlwaysOnTop  +Owner +Resize +ToolWindow ; window for the dock
  Gui, Show, NoActivate w%ww% h%hh% x%xx% y%yy% , PrintScreen
  Gui, Add, DDL, vzoom   , 0.5|1|2||4|8|16 
  Gui, Add, Checkbox, y12 x150 vantialize, Antialize ?
  Gui, Add, Slider, vdelay x220 y0  Range15-200
  Gui, Add, Text, x340 y12 w80  vdelay2

  WinGet PrintScreenID, id  ,PrintScreen  ; 
  WinSet, Transparent , 254, PrintScreen

  ;retrieve the unique ID number (HWND/handle) of that window
  WinGet, PrintSourceID, id 

  hotkey , #x           , toggle_follow
  hotkey , +$LButton    , click_through

  toolbar_def:=35
  toolbar := toolbar_def
  follow :=0

  hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
  hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )

  hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)  ; buffer
  hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
  
  Gosub, Repaint
return 

toggle_follow: 
    follow := 1 - follow
  
    if follow = 1 
    {
        WinSet Region, 0-0  W%ww% H%wh% E  , PrintScreen
        toolbar := -32 ; height of window title
        GuiControl, Hide, zoom
    }
    else
    {
        WinSet Region,, PrintScreen
        toolbar :=toolbar_def
        GuiControl, Show, zoom
    }
Return

click_through:
    if follow = 1
    {
      Gui, Hide
      Send, {Click}
      SetTimer, Repaint , Off
      Sleep, 100
      Gui, Show
      SetTimer, Repaint, %delay%
    }
Return

Repaint: 

   CoordMode, Mouse, Screen                
   ;MouseGetPos, start_x, start_y             ;  position of mouse
   Gui, Submit, NoHide                       ; needed to read the dropdown and slidervalue
   GuiControl,, delay2 , delay %delay% ms
   WinGetPos, wx, wy, ww, wh , PrintScreen

   wh2 := wh - toolbar

    DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )  ; Halftone better quality with stretch
   
    DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,toolbar, Int,ww, Int,wh - toolbar
          , UInt,hdd_frame, Int
          , start_x-(ww / 2 / zoom)
          , Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020) ; SRCCOPY

   if follow = 1
     WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2 
   
  SetTimer, Repaint , %delay% 
Return

GuiClose:
handle_exit:
   DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp

Script of resources (need to use the focus on center of screen from this script, so that the magnifier will not follow mouse cursor)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=380, yy:= 164, ww:=600, hh:=440

;ScreenMagnifier from holomind 
;https://autohotkey.com/board/topic/10660-screenmagnifier/
OnExit handle_exit

  Gui,  +AlwaysOnTop  +Owner +Resize +ToolWindow ; window for the dock
  Gui, Show, NoActivate w%ww% h%hh% x%xx% y%yy% , PrintScreen
  Gui, Add, DDL, vzoom   , 0.5|1|2||4|8|16 
  Gui, Add, Checkbox, y12 x150 vantialize, Antialize ?
  Gui, Add, Slider, vdelay x220 y0  Range1-200
  Gui, Add, Text, x340 y12 w80  vdelay2

  WinGet PrintScreenID, id  ,PrintScreen  ; 
  WinSet, Transparent , 254, PrintScreen

  ;retrieve the unique ID number (HWND/handle) of that window
  WinGet, PrintSourceID, id 

  hotkey , #x           , toggle_follow
  hotkey , +$LButton    , click_through

  toolbar_def:=35
  toolbar := toolbar_def
  follow :=0

  hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
  hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )

  hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)  ; buffer
  hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
  
  Gosub, Repaint
return 

toggle_follow: 
    follow := 1 - follow
  
    if follow = 1 
    {
        WinSet Region, 0-0  W%ww% H%wh% E  , PrintScreen
        toolbar := -32 ; height of window title
        GuiControl, Hide, zoom
    }
    else
    {
        WinSet Region,, PrintScreen
        toolbar :=toolbar_def
        GuiControl, Show, zoom
    }
Return

click_through:
    if follow = 1
    {
      Gui, Hide
      Send, {Click}
      SetTimer, Repaint , Off
      Sleep, 100
      Gui, Show
      SetTimer, Repaint, %delay%
    }
Return

Repaint: 

   CoordMode, Mouse, Screen                
   ;MouseGetPos, start_x, start_y             ;  position of mouse
   Gui, Submit, NoHide                       ; needed to read the dropdown and slidervalue
   GuiControl,, delay2 , delay %delay% ms
   WinGetPos, wx, wy, ww, wh , PrintScreen

   wh2 := wh - toolbar

    DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )  ; Halftone better quality with stretch
   
    DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,toolbar, Int,ww, Int,wh - toolbar
          , UInt,hdd_frame, Int
          , start_x-(ww / 2 / zoom)
          , Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020) ; SRCCOPY

   if follow = 1
     WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2 
   
  SetTimer, Repaint , %delay% 
Return

GuiClose:
handle_exit:
   DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp
Thank you for reading
Last edited by Monomoy on 07 Sep 2019, 08:10, edited 17 times in total.
User avatar
Chunjee
Posts: 1421
Joined: 18 Apr 2014, 19:05
Contact:

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

27 Aug 2019, 12:22

This should be in the gaming area. Also I have no idea what "The problems that I am having now with both of these two scripts are the overlapping windows" means.

It sounds like you are just having trouble making the zoom toggle?
User avatar
Dumitas
Posts: 167
Joined: 14 Dec 2017, 21:32

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

27 Aug 2019, 12:37

At least in the second one just add a hotkey before the first label subroutine:

Code: Select all

 ;hotkey here
key_to_scope:
Image
User avatar
Dumitas
Posts: 167
Joined: 14 Dec 2017, 21:32

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

27 Aug 2019, 17:13

Sorry I assumed you understand the basics.

Code: Select all

;This is just a comment
What I mean is add a literal hotkey

Code: Select all

x:: ;This for example (can be any key)
key_to_scope:
You toggle it with "x" in this example.
Image
gregster
Posts: 9012
Joined: 30 Sep 2013, 06:48

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

27 Aug 2019, 17:38

Monomoy wrote:
27 Aug 2019, 14:20
I have not yet learned how to post pictures on this forum but if you have discord feel free to contact me there and I will send pictures as attachment
If you scroll down from the edit box, you can add up to 3 pictures per post via Attachments > Add files > (wait shortly until picture is loaded) > (optionally click 'Place inline' if you want the picture inserted at last cursor position rather than at the end of your post):

Upload images.png
Upload images.png (6.26 KiB) Viewed 6841 times

(this picture is "placed inline" - you can continue with text below the picture)
Monomoy
Posts: 34
Joined: 27 Aug 2019, 11:11

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

27 Aug 2019, 18:56

Ok I have updated the thread and code
User avatar
Dumitas
Posts: 167
Joined: 14 Dec 2017, 21:32

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

27 Aug 2019, 19:11

Use this one from ScreenMagnifier by Holomind
Or resize the others

Code: Select all

#NoEnv
SetBatchLines -1

CoordMode Mouse, Screen
OnExit GuiClose
zoom = 2                ; initial magnification, 1..32
antialize = 0
Rx = 128                ; half vertical/horizontal side of magnifier window
Ry = 128
Zx := Rx/zoom           ; frame x/y size
Zy := Ry/zoom
                        ; GUI to show the magnified image
Gui +AlwaysOnTop +Resize +ToolWindow
Gui Show, % "w" 2*Rx " h" 2*Ry " x0 y0", Magnifier
WinGet MagnifierID, id,  Magnifier
WinSet Transparent, 255, Magnifier ; makes the window invisible to magnification
WinGet PrintSourceID, ID

hdd_frame := DllCall("GetDC", UInt, PrintSourceID)
hdc_frame := DllCall("GetDC", UInt, MagnifierID)

SetTimer Repaint, 50    ; flow through

Repaint:
   MouseGetPos x, y
   xz := In(x-Zx-6,0,A_ScreenWidth-2*Zx) ; keep the frame on screen
   yz := In(y-Zy-6,0,A_ScreenHeight-2*Zy)
  ; WinMove Frame,,%xz%, %yz%, % 2*Zx, % 2*Zy
   DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,0, Int,2*Rx, Int,2*Ry
   , UInt,hdd_frame, UInt,xz, UInt,yz, Int,2*Zx, Int,2*Zy, UInt,0xCC0020) ; SRCCOPY
Return


GuiSize:
   Rx := A_GuiWidth/2
   Ry := A_GuiHeight/2
   Zx := Rx/zoom
   Zy := Ry/zoom
   TrayTip,,% "Frame  =  " Round(2*Zx) " × " Round(2*Zy) "`nMagnified to = " A_GuiWidth "×" A_GuiHeight
Return

#a::
  antialize := !antialize
  DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4*antialize )  ; Antializing ?
Return 

#x::
GuiClose:
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
ExitApp

#p::
MButton::
   if paused = 
   {
        Gui, 2:Hide 
        Gui, Hide 
        SetTimer, Repaint, Off
        paused = 1
   }
   else
   {
        Gui, 2:Show 
        Gui, Show 
        SetTimer, Repaint, 50
        paused =
   }
Return

^+Up::
^+Down::
^+WheelUp::                      ; Ctrl+Shift+WheelUp to zoom in
^+WheelDown::                    ; Ctrl+Shift+WheelUp to zoom out
   If (zoom < 31 and ( A_ThisHotKey = "^+WheelUp" or A_ThisHotKey = "^+Up" ))
      zoom *= 1.189207115         ; sqrt(sqrt(2))
   If (zoom >  1 and ( A_ThisHotKey = "^+WheelDown" or A_ThisHotKey = "^+Down" ))
      zoom /= 1.189207115
   Zx := Rx/zoom
   Zy := Ry/zoom
   TrayTip,,% "Zoom = " Round(100*zoom) "%"
Return

In(x,a,b) {                      ; closest number to x in [a,b]
   IfLess x,%a%, Return a
   IfLess b,%x%, Return b
   Return x
}
You can't have the zoom in the middle of the screen, the overlapping will always happen, since you are watching the magnifier through the magnifier. With this one, you can move it to a side, and play it that way.
Image
Monomoy
Posts: 34
Joined: 27 Aug 2019, 11:11

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

27 Aug 2019, 20:31

Dumitas wrote:
27 Aug 2019, 19:11
Use this one from ScreenMagnifier by Holomind
Or resize the others

Code: Select all

#NoEnv
SetBatchLines -1

CoordMode Mouse, Screen
OnExit GuiClose
zoom = 2                ; initial magnification, 1..32
antialize = 0
Rx = 128                ; half vertical/horizontal side of magnifier window
Ry = 128
Zx := Rx/zoom           ; frame x/y size
Zy := Ry/zoom
                        ; GUI to show the magnified image
Gui +AlwaysOnTop +Resize +ToolWindow
Gui Show, % "w" 2*Rx " h" 2*Ry " x0 y0", Magnifier
WinGet MagnifierID, id,  Magnifier
WinSet Transparent, 255, Magnifier ; makes the window invisible to magnification
WinGet PrintSourceID, ID

hdd_frame := DllCall("GetDC", UInt, PrintSourceID)
hdc_frame := DllCall("GetDC", UInt, MagnifierID)

SetTimer Repaint, 50    ; flow through

Repaint:
   MouseGetPos x, y
   xz := In(x-Zx-6,0,A_ScreenWidth-2*Zx) ; keep the frame on screen
   yz := In(y-Zy-6,0,A_ScreenHeight-2*Zy)
  ; WinMove Frame,,%xz%, %yz%, % 2*Zx, % 2*Zy
   DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,0, Int,2*Rx, Int,2*Ry
   , UInt,hdd_frame, UInt,xz, UInt,yz, Int,2*Zx, Int,2*Zy, UInt,0xCC0020) ; SRCCOPY
Return


GuiSize:
   Rx := A_GuiWidth/2
   Ry := A_GuiHeight/2
   Zx := Rx/zoom
   Zy := Ry/zoom
   TrayTip,,% "Frame  =  " Round(2*Zx) " × " Round(2*Zy) "`nMagnified to = " A_GuiWidth "×" A_GuiHeight
Return

#a::
  antialize := !antialize
  DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4*antialize )  ; Antializing ?
Return 

#x::
GuiClose:
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
ExitApp

#p::
MButton::
   if paused = 
   {
        Gui, 2:Hide 
        Gui, Hide 
        SetTimer, Repaint, Off
        paused = 1
   }
   else
   {
        Gui, 2:Show 
        Gui, Show 
        SetTimer, Repaint, 50
        paused =
   }
Return

^+Up::
^+Down::
^+WheelUp::                      ; Ctrl+Shift+WheelUp to zoom in
^+WheelDown::                    ; Ctrl+Shift+WheelUp to zoom out
   If (zoom < 31 and ( A_ThisHotKey = "^+WheelUp" or A_ThisHotKey = "^+Up" ))
      zoom *= 1.189207115         ; sqrt(sqrt(2))
   If (zoom >  1 and ( A_ThisHotKey = "^+WheelDown" or A_ThisHotKey = "^+Down" ))
      zoom /= 1.189207115
   Zx := Rx/zoom
   Zy := Ry/zoom
   TrayTip,,% "Zoom = " Round(100*zoom) "%"
Return

In(x,a,b) {                      ; closest number to x in [a,b]
   IfLess x,%a%, Return a
   IfLess b,%x%, Return b
   Return x
}
You can't have the zoom in the middle of the screen, the overlapping will always happen, since you are watching the magnifier through the magnifier. With this one, you can move it to a side, and play it that way.

"Due to a trick and using transparent 254 the window appears solid, but is invisible for BitBlt (DC_Copy), so the window does not copy itself and you even can magnify regions behind the loupe- window!"

When I use the script (Screen Magnifier) I still get the window in a window

https://autohotkey.com/board/topic/10660-screenmagnifier/

these are the differences I noticed in the script that may be relevant to avoiding the window in a window
"WinSet Transparent, 255, Magnifier ; makes the window invisible to magnification" Line 21(Screen Magnifier)
"WinSet Transparent, 254, PrintScreen" Line 28 (Scope Window AHK)

How do I set the zoom coordinates to the middle of the screen rather than following the mouse cursor?
Screen Magnifier from Holomind works fine and there are comments at the top of the code for adding absolute x,y magnification, but I can't find where in the code this is being controlled as it seems very similar to "Scope Window AHK" except for ;MouseGetPos in line 68

I think "Scope Window AHK" is using

Code: Select all

Repaint:
CoordMode, Mouse, Screen
MouseGetPos, start_x, start_y
but I really just want it to lock onto certain coordinates with

Code: Select all

; the specific (absolute) x, y to be magnified,
start_x= 680, start_y= 384
; the display of the magnified image x, y, w, h
xx=000, yy= 00, ww=400, hh=400
and I was unable to find a command for setting coordinates on specific x,y like the center of screen after browsing here: https://www.autohotkey.com/docs/commands/index.htm
Monomoy
Posts: 34
Joined: 27 Aug 2019, 11:11

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

28 Aug 2019, 18:52

Please help I think the script is very close just needs absolute magnification coordinates to be added (instead of following the mouse)(the provided script "Screen Magnifier" has a functioning version of this I just don't know what code is controlling the function and the way to add this function into "Scope Window AHK" and a fix for getting the window inside a window

I've made some changes to the original post adding another AHK script and thread as a resource



Bump
Monomoy
Posts: 34
Joined: 27 Aug 2019, 11:11

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

04 Sep 2019, 16:05

It has been a few days so I want to update

the script only needs a to focus on the center of the screen and not the mouse movement which exists in another script that i've posted, i just don't know what the differences are in the code causing this to happen

also is there a way to have the fix the magnifier inside the magnifier?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

05 Sep 2019, 05:45

Btw compare using = and :=.

Code: Select all

start_x= 680, start_y= 384
MsgBox, % start_x ;680, start_y= 384
start_x:= 680, start_y:= 384
MsgBox, % start_x ;680

xx=000, yy= 00, ww=400, hh=400
MsgBox, % xx ;000, yy= 00, ww=400, hh=400
xx:=000, yy:= 00, ww:=400, hh:=400
MsgBox, % xx ;000
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Monomoy
Posts: 34
Joined: 27 Aug 2019, 11:11

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

05 Sep 2019, 08:43

jeeswg wrote:
05 Sep 2019, 05:45
Btw compare using = and :=.

Code: Select all

start_x= 680, start_y= 384
MsgBox, % start_x ;680, start_y= 384
start_x:= 680, start_y:= 384
MsgBox, % start_x ;680

xx=000, yy= 00, ww=400, hh=400
MsgBox, % xx ;000, yy= 00, ww=400, hh=400
xx:=000, yy:= 00, ww:=400, hh:=400
MsgBox, % xx ;000
@jeeswg i've added some of the edits and updated the thread, but i don't understand the function of MsgBox parameter
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

05 Sep 2019, 09:28

I often use MsgBox to print (display) a variable's contents.
MsgBox, % var
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Monomoy
Posts: 34
Joined: 27 Aug 2019, 11:11

Re: Zoom Function for FPS (Scripts Provided)(Need Help to Finish)

05 Sep 2019, 19:34

i'm having problems with this light gray bar leftover at the top of the magnified window

i've tried removing the toolbar and gui options

don't know why there is a grey bar running from top right to top left, occupying the window where the toolbar used to be

for now i've used -x, -y coordinates to clip the grey box offscreen
94184109676f441c5a602153e50e2584.png
94184109676f441c5a602153e50e2584.png (40.21 KiB) Viewed 6366 times
Last edited by Monomoy on 07 Sep 2019, 08:11, edited 1 time in total.
Monomoy
Posts: 34
Joined: 27 Aug 2019, 11:11

Re: Zoom Function for FPS (Scripts Provided)

07 Sep 2019, 08:10

Is there anyway to have the magnifier not detect the magnified window? Preventing the magnifier inside magnifier
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Zoom Function for FPS (Scripts Provided)

07 Sep 2019, 09:03

Is there anyway to have the magnifier not detect the magnified window? Preventing the magnifier inside magnifier
I made a zoom script, see :arrow: [UCR Plugins] Zoom.ahk, it cannot zoom itself. I didn't read all the requirements in this thread so I don't know if it is relevant.

Cheers.
ThewarII
Posts: 49
Joined: 01 Oct 2014, 09:33

Re: Zoom Function for FPS (Scripts Provided)

23 Oct 2021, 00:28

Monomoy wrote:
27 Aug 2019, 11:29
These are the two scripts I have found by googling online and have attempted to make small edits to both already

*
Script in Progress:

Code: Select all

#Persistent
#NoEnv
Menu,Tray,NoStandard
OnExit handle_exit

State=0

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=000, yy:= 00, ww:=400, hh:=400

Alt:: ;hotkey here

key_to_scope:
State:=!State
send {Ctrl up}
send {Ctrl down}
send {Ctrl up}
If state
{
Gui,  +AlwaysOnTop  +E0x20 -Caption +Owner +Resize -ToolWindow
Gui, Show, NoActivate w300 h220 x0 y0 , PrintScreen
zoom:=1
antialize:=1
delay:=1
WinGet PrintScreenID, id  ,PrintScreen
WinSet Transparent, 254, PrintScreen
WinGet, PrintSourceID, id
hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )
hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)
hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
Gosub, Repaint
return
Repaint:
CoordMode, Mouse, Screen
MouseGetPos, start_x, start_y
Gui, Submit, NoHide
GuiControl,, delay2 , delay %delay% ms
WinGetPos, wx, wy, ww, wh , PrintScreen
wh2 := wh
DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )
DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,0, Int,ww, Int,wh
, UInt,hdd_frame, Int
, start_x-(ww / 2 / zoom)
, Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020)
if follow = 1
WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2
SetTimer, Repaint , %delay%
Return
GuiClose:
handle_exit:
DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp xxxxx
}
Else
Gui Destroy
Return

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Screen Magnifier by Holomind

Code: Select all

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=000, yy:= 00, ww:=400, hh:=400

;ScreenMagnifier from holomind 
;https://autohotkey.com/board/topic/10660-screenmagnifier/
OnExit handle_exit

  Gui,  +AlwaysOnTop  +Owner +Resize +ToolWindow ; window for the dock
  Gui, Show, NoActivate w%ww% h%hh% x%xx% y%yy% , PrintScreen
  Gui, Add, DDL, vzoom   , 0.5|1|2||4|8|16 
  Gui, Add, Checkbox, y12 x150 vantialize, Antialize ?
  Gui, Add, Slider, vdelay x220 y0  Range15-200
  Gui, Add, Text, x340 y12 w80  vdelay2

  WinGet PrintScreenID, id  ,PrintScreen  ; 
  WinSet, Transparent , 254, PrintScreen

  ;retrieve the unique ID number (HWND/handle) of that window
  WinGet, PrintSourceID, id 

  hotkey , #x           , toggle_follow
  hotkey , +$LButton    , click_through

  toolbar_def:=35
  toolbar := toolbar_def
  follow :=0

  hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
  hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )

  hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)  ; buffer
  hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
  
  Gosub, Repaint
return 

toggle_follow: 
    follow := 1 - follow
  
    if follow = 1 
    {
        WinSet Region, 0-0  W%ww% H%wh% E  , PrintScreen
        toolbar := -32 ; height of window title
        GuiControl, Hide, zoom
    }
    else
    {
        WinSet Region,, PrintScreen
        toolbar :=toolbar_def
        GuiControl, Show, zoom
    }
Return

click_through:
    if follow = 1
    {
      Gui, Hide
      Send, {Click}
      SetTimer, Repaint , Off
      Sleep, 100
      Gui, Show
      SetTimer, Repaint, %delay%
    }
Return

Repaint: 

   CoordMode, Mouse, Screen                
   ;MouseGetPos, start_x, start_y             ;  position of mouse
   Gui, Submit, NoHide                       ; needed to read the dropdown and slidervalue
   GuiControl,, delay2 , delay %delay% ms
   WinGetPos, wx, wy, ww, wh , PrintScreen

   wh2 := wh - toolbar

    DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )  ; Halftone better quality with stretch
   
    DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,toolbar, Int,ww, Int,wh - toolbar
          , UInt,hdd_frame, Int
          , start_x-(ww / 2 / zoom)
          , Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020) ; SRCCOPY

   if follow = 1
     WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2 
   
  SetTimer, Repaint , %delay% 
Return

GuiClose:
handle_exit:
   DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp

Script of resources (need to use the focus on center of screen from this script, so that the magnifier will not follow mouse cursor)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=380, yy:= 164, ww:=600, hh:=440

;ScreenMagnifier from holomind 
;https://autohotkey.com/board/topic/10660-screenmagnifier/
OnExit handle_exit

  Gui,  +AlwaysOnTop  +Owner +Resize +ToolWindow ; window for the dock
  Gui, Show, NoActivate w%ww% h%hh% x%xx% y%yy% , PrintScreen
  Gui, Add, DDL, vzoom   , 0.5|1|2||4|8|16 
  Gui, Add, Checkbox, y12 x150 vantialize, Antialize ?
  Gui, Add, Slider, vdelay x220 y0  Range1-200
  Gui, Add, Text, x340 y12 w80  vdelay2

  WinGet PrintScreenID, id  ,PrintScreen  ; 
  WinSet, Transparent , 254, PrintScreen

  ;retrieve the unique ID number (HWND/handle) of that window
  WinGet, PrintSourceID, id 

  hotkey , #x           , toggle_follow
  hotkey , +$LButton    , click_through

  toolbar_def:=35
  toolbar := toolbar_def
  follow :=0

  hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
  hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )

  hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)  ; buffer
  hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
  
  Gosub, Repaint
return 

toggle_follow: 
    follow := 1 - follow
  
    if follow = 1 
    {
        WinSet Region, 0-0  W%ww% H%wh% E  , PrintScreen
        toolbar := -32 ; height of window title
        GuiControl, Hide, zoom
    }
    else
    {
        WinSet Region,, PrintScreen
        toolbar :=toolbar_def
        GuiControl, Show, zoom
    }
Return

click_through:
    if follow = 1
    {
      Gui, Hide
      Send, {Click}
      SetTimer, Repaint , Off
      Sleep, 100
      Gui, Show
      SetTimer, Repaint, %delay%
    }
Return

Repaint: 

   CoordMode, Mouse, Screen                
   ;MouseGetPos, start_x, start_y             ;  position of mouse
   Gui, Submit, NoHide                       ; needed to read the dropdown and slidervalue
   GuiControl,, delay2 , delay %delay% ms
   WinGetPos, wx, wy, ww, wh , PrintScreen

   wh2 := wh - toolbar

    DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )  ; Halftone better quality with stretch
   
    DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,toolbar, Int,ww, Int,wh - toolbar
          , UInt,hdd_frame, Int
          , start_x-(ww / 2 / zoom)
          , Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020) ; SRCCOPY

   if follow = 1
     WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2 
   
  SetTimer, Repaint , %delay% 
Return

GuiClose:
handle_exit:
   DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp
Thank you for reading
Thank for your script and i edited to like below:

Code: Select all

;Source : "https://www.autohotkey.com/boards/viewtopic.php?t=67467"
;========================================================
#SingleInstance, Force
#Persistent
#NoEnv
Menu,Tray,NoStandard
OnExit handle_exit
;ListLines
State=0

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=000, yy:= 00, ww:=400, hh:=400

RAlt:: ;hotkey here
zoom:=1 ; thay doi Zoom o day.
key_to_scope:
State:=!State
send {Ctrl up}
send {Ctrl down}
send {Ctrl up}
If state
{
	Gui,  +AlwaysOnTop  +E0x20 -Caption +Owner +Resize -ToolWindow
	Gui, Show, NoActivate w300 h220 x0 y0 , PrintScreen
	antialize:=1
	delay:=1
	ShowGui := 2
	WinGet PrintScreenID, id  ,PrintScreen
	WinSet Transparent, 254, PrintScreen
	WinGet, PrintSourceID, id
	hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
	hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )
	hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)
	hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
	Gosub, Repaint
	return
	Repaint:
	CoordMode, Mouse, Screen
	MouseGetPos, start_x, start_y
	If (start_x < 320 && start_y < 240)
	{
		If (ShowGui = 2)
		{
			Gui, Show, NoActivate w300 h220 x1620 y0 , PrintScreen
		}
		ShowGui := 1
	}
	Else
	{
		If (ShowGui = 1)
		{
			Gui, Show, NoActivate w300 h220 x0 y0 , PrintScreen
		}
		ShowGui := 2
	}
	Gui, Submit, NoHide
	GuiControl,, delay2 , delay %delay% ms
	WinGetPos, wx, wy, ww, wh , PrintScreen
	wh2 := wh
	DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )
	DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,0, Int,ww, Int,wh
	, UInt,hdd_frame, Int
	, start_x-(ww / 2 / zoom)
	, Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020)
	if follow = 1
	WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2
	SetTimer, Repaint , %delay%
	Return
}
Else
Gui Destroy
Return

$WheelUp::
If state
{
	Zoom += 1
	If (Zoom > 64)
	{
		Zoom := 64
	}
}
Else
{
	Send,{WheelUp}
}
Return

$WheelDown::
If state
{
	Zoom -= 1
	If (Zoom < 1)
	{
		Zoom := 1
	}
}
Else
{
	Send,{WheelDown}
}
Return

~!r::
SoundBeep,
Reload
Return

~!x::
SoundBeep,8500,150
GuiClose:
handle_exit:
DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp xxxxx
Return
I :superhappy:(happy) when I know about AHK.
I have & am using AHK to do anything in windows microsoft.
The first time, I know it in around year 2013.
sakuchi139595
Posts: 8
Joined: 09 Apr 2022, 23:42

Re: Zoom Function for FPS (Scripts Provided)

13 May 2022, 06:56

hi how doest it work?, How to enable it?
sakuchi139595
Posts: 8
Joined: 09 Apr 2022, 23:42

Re: Zoom Function for FPS (Scripts Provided)

13 May 2022, 06:57

Monomoy wrote:
27 Aug 2019, 11:29
If you would like to, contact me on Discord: Monomoy#8291

I'm having difficulty posting youtube video on the forum without the link breaking
___________________________________________________________________

I'm playing on 1360x768
I want the ability to toggle zoom in on the center of the screen (centerpoint for my resolution is 680 384)(not sure how large the magnified window needs to be)
This will allow the player to zoom in without aiming down the sights

It is useful because aiming down the sights will cause some objects to render in at distance (grass, bushes, trees)
Also useful because some factions are ironsight only and do not have scopes, so this will allow ironsight classes to be competitive against scopes at range
Additionally, some kits are not provided binoculars

I've searched the internet for quite awhile and found two AHK scripts that are nearly functional
viewtopic.php?t=29270

In addition to this relevant thread (Screen Magnifier V2)
viewtopic.php?t=29270



The problems that I am having now:

The magnifier focus is following the mouse cursor when I just want it to lock on the middle of the screen coordinates then draw a viewing box 400 pixels large

The magnified window overlapping, is there a way to have the magnifier window be transparent to itself?

b0ff77c616cc5a96782199addd8e9347.png




Here are some examples of the effect this would have in a FPS game

EsRRZbh.png

KtZTC0v.png

[ youtube ] https :// www.youtube.com /watch?v=7k6SitNNxnc[ / youtube ] Broken Link for safety

__________________________________________________________________________________________________________________________________________

These are the two scripts I have found by googling online and have attempted to make small edits to both already

*
Script in Progress:

Code: Select all

#Persistent
#NoEnv
Menu,Tray,NoStandard
OnExit handle_exit

State=0

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=000, yy:= 00, ww:=400, hh:=400

Alt:: ;hotkey here

key_to_scope:
State:=!State
send {Ctrl up}
send {Ctrl down}
send {Ctrl up}
If state
{
Gui,  +AlwaysOnTop  +E0x20 -Caption +Owner +Resize -ToolWindow
Gui, Show, NoActivate w300 h220 x0 y0 , PrintScreen
zoom:=1
antialize:=1
delay:=1
WinGet PrintScreenID, id  ,PrintScreen
WinSet Transparent, 254, PrintScreen
WinGet, PrintSourceID, id
hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )
hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)
hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
Gosub, Repaint
return
Repaint:
CoordMode, Mouse, Screen
MouseGetPos, start_x, start_y
Gui, Submit, NoHide
GuiControl,, delay2 , delay %delay% ms
WinGetPos, wx, wy, ww, wh , PrintScreen
wh2 := wh
DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )
DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,0, Int,ww, Int,wh
, UInt,hdd_frame, Int
, start_x-(ww / 2 / zoom)
, Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020)
if follow = 1
WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2
SetTimer, Repaint , %delay%
Return
GuiClose:
handle_exit:
DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp xxxxx
}
Else
Gui Destroy
Return

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Screen Magnifier by Holomind

Code: Select all

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=000, yy:= 00, ww:=400, hh:=400

;ScreenMagnifier from holomind 
;https://autohotkey.com/board/topic/10660-screenmagnifier/
OnExit handle_exit

  Gui,  +AlwaysOnTop  +Owner +Resize +ToolWindow ; window for the dock
  Gui, Show, NoActivate w%ww% h%hh% x%xx% y%yy% , PrintScreen
  Gui, Add, DDL, vzoom   , 0.5|1|2||4|8|16 
  Gui, Add, Checkbox, y12 x150 vantialize, Antialize ?
  Gui, Add, Slider, vdelay x220 y0  Range15-200
  Gui, Add, Text, x340 y12 w80  vdelay2

  WinGet PrintScreenID, id  ,PrintScreen  ; 
  WinSet, Transparent , 254, PrintScreen

  ;retrieve the unique ID number (HWND/handle) of that window
  WinGet, PrintSourceID, id 

  hotkey , #x           , toggle_follow
  hotkey , +$LButton    , click_through

  toolbar_def:=35
  toolbar := toolbar_def
  follow :=0

  hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
  hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )

  hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)  ; buffer
  hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
  
  Gosub, Repaint
return 

toggle_follow: 
    follow := 1 - follow
  
    if follow = 1 
    {
        WinSet Region, 0-0  W%ww% H%wh% E  , PrintScreen
        toolbar := -32 ; height of window title
        GuiControl, Hide, zoom
    }
    else
    {
        WinSet Region,, PrintScreen
        toolbar :=toolbar_def
        GuiControl, Show, zoom
    }
Return

click_through:
    if follow = 1
    {
      Gui, Hide
      Send, {Click}
      SetTimer, Repaint , Off
      Sleep, 100
      Gui, Show
      SetTimer, Repaint, %delay%
    }
Return

Repaint: 

   CoordMode, Mouse, Screen                
   ;MouseGetPos, start_x, start_y             ;  position of mouse
   Gui, Submit, NoHide                       ; needed to read the dropdown and slidervalue
   GuiControl,, delay2 , delay %delay% ms
   WinGetPos, wx, wy, ww, wh , PrintScreen

   wh2 := wh - toolbar

    DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )  ; Halftone better quality with stretch
   
    DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,toolbar, Int,ww, Int,wh - toolbar
          , UInt,hdd_frame, Int
          , start_x-(ww / 2 / zoom)
          , Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020) ; SRCCOPY

   if follow = 1
     WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2 
   
  SetTimer, Repaint , %delay% 
Return

GuiClose:
handle_exit:
   DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp

Script of resources (need to use the focus on center of screen from this script, so that the magnifier will not follow mouse cursor)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=380, yy:= 164, ww:=600, hh:=440

;ScreenMagnifier from holomind 
;https://autohotkey.com/board/topic/10660-screenmagnifier/
OnExit handle_exit

  Gui,  +AlwaysOnTop  +Owner +Resize +ToolWindow ; window for the dock
  Gui, Show, NoActivate w%ww% h%hh% x%xx% y%yy% , PrintScreen
  Gui, Add, DDL, vzoom   , 0.5|1|2||4|8|16 
  Gui, Add, Checkbox, y12 x150 vantialize, Antialize ?
  Gui, Add, Slider, vdelay x220 y0  Range1-200
  Gui, Add, Text, x340 y12 w80  vdelay2

  WinGet PrintScreenID, id  ,PrintScreen  ; 
  WinSet, Transparent , 254, PrintScreen

  ;retrieve the unique ID number (HWND/handle) of that window
  WinGet, PrintSourceID, id 

  hotkey , #x           , toggle_follow
  hotkey , +$LButton    , click_through

  toolbar_def:=35
  toolbar := toolbar_def
  follow :=0

  hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
  hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )

  hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)  ; buffer
  hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
  
  Gosub, Repaint
return 

toggle_follow: 
    follow := 1 - follow
  
    if follow = 1 
    {
        WinSet Region, 0-0  W%ww% H%wh% E  , PrintScreen
        toolbar := -32 ; height of window title
        GuiControl, Hide, zoom
    }
    else
    {
        WinSet Region,, PrintScreen
        toolbar :=toolbar_def
        GuiControl, Show, zoom
    }
Return

click_through:
    if follow = 1
    {
      Gui, Hide
      Send, {Click}
      SetTimer, Repaint , Off
      Sleep, 100
      Gui, Show
      SetTimer, Repaint, %delay%
    }
Return

Repaint: 

   CoordMode, Mouse, Screen                
   ;MouseGetPos, start_x, start_y             ;  position of mouse
   Gui, Submit, NoHide                       ; needed to read the dropdown and slidervalue
   GuiControl,, delay2 , delay %delay% ms
   WinGetPos, wx, wy, ww, wh , PrintScreen

   wh2 := wh - toolbar

    DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )  ; Halftone better quality with stretch
   
    DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,toolbar, Int,ww, Int,wh - toolbar
          , UInt,hdd_frame, Int
          , start_x-(ww / 2 / zoom)
          , Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020) ; SRCCOPY

   if follow = 1
     WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2 
   
  SetTimer, Repaint , %delay% 
Return

GuiClose:
handle_exit:
   DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp
Thank you for reading

Hi how does it work?, How to enable it
Monomoy
Posts: 34
Joined: 27 Aug 2019, 11:11

Re: Zoom Function for FPS (Scripts Provided)

30 May 2022, 13:20

sakuchi139595 wrote:
13 May 2022, 06:57
Monomoy wrote:
27 Aug 2019, 11:29
If you would like to, contact me on Discord: Monomoy#8291

I'm having difficulty posting youtube video on the forum without the link breaking
___________________________________________________________________

I'm playing on 1360x768
I want the ability to toggle zoom in on the center of the screen (centerpoint for my resolution is 680 384)(not sure how large the magnified window needs to be)
This will allow the player to zoom in without aiming down the sights

It is useful because aiming down the sights will cause some objects to render in at distance (grass, bushes, trees)
Also useful because some factions are ironsight only and do not have scopes, so this will allow ironsight classes to be competitive against scopes at range
Additionally, some kits are not provided binoculars

I've searched the internet for quite awhile and found two AHK scripts that are nearly functional
viewtopic.php?t=29270

In addition to this relevant thread (Screen Magnifier V2)
viewtopic.php?t=29270



The problems that I am having now:

The magnifier focus is following the mouse cursor when I just want it to lock on the middle of the screen coordinates then draw a viewing box 400 pixels large

The magnified window overlapping, is there a way to have the magnifier window be transparent to itself?

b0ff77c616cc5a96782199addd8e9347.png




Here are some examples of the effect this would have in a FPS game

EsRRZbh.png

KtZTC0v.png

[ youtube ] https :// www.youtube.com /watch?v=7k6SitNNxnc[ / youtube ] Broken Link for safety

__________________________________________________________________________________________________________________________________________

These are the two scripts I have found by googling online and have attempted to make small edits to both already

*
Script in Progress:

Code: Select all

#Persistent
#NoEnv
Menu,Tray,NoStandard
OnExit handle_exit

State=0

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=000, yy:= 00, ww:=400, hh:=400

Alt:: ;hotkey here

key_to_scope:
State:=!State
send {Ctrl up}
send {Ctrl down}
send {Ctrl up}
If state
{
Gui,  +AlwaysOnTop  +E0x20 -Caption +Owner +Resize -ToolWindow
Gui, Show, NoActivate w300 h220 x0 y0 , PrintScreen
zoom:=1
antialize:=1
delay:=1
WinGet PrintScreenID, id  ,PrintScreen
WinSet Transparent, 254, PrintScreen
WinGet, PrintSourceID, id
hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )
hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)
hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
Gosub, Repaint
return
Repaint:
CoordMode, Mouse, Screen
MouseGetPos, start_x, start_y
Gui, Submit, NoHide
GuiControl,, delay2 , delay %delay% ms
WinGetPos, wx, wy, ww, wh , PrintScreen
wh2 := wh
DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )
DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,0, Int,ww, Int,wh
, UInt,hdd_frame, Int
, start_x-(ww / 2 / zoom)
, Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020)
if follow = 1
WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2
SetTimer, Repaint , %delay%
Return
GuiClose:
handle_exit:
DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp xxxxx
}
Else
Gui Destroy
Return

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Screen Magnifier by Holomind

Code: Select all

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=000, yy:= 00, ww:=400, hh:=400

;ScreenMagnifier from holomind 
;https://autohotkey.com/board/topic/10660-screenmagnifier/
OnExit handle_exit

  Gui,  +AlwaysOnTop  +Owner +Resize +ToolWindow ; window for the dock
  Gui, Show, NoActivate w%ww% h%hh% x%xx% y%yy% , PrintScreen
  Gui, Add, DDL, vzoom   , 0.5|1|2||4|8|16 
  Gui, Add, Checkbox, y12 x150 vantialize, Antialize ?
  Gui, Add, Slider, vdelay x220 y0  Range15-200
  Gui, Add, Text, x340 y12 w80  vdelay2

  WinGet PrintScreenID, id  ,PrintScreen  ; 
  WinSet, Transparent , 254, PrintScreen

  ;retrieve the unique ID number (HWND/handle) of that window
  WinGet, PrintSourceID, id 

  hotkey , #x           , toggle_follow
  hotkey , +$LButton    , click_through

  toolbar_def:=35
  toolbar := toolbar_def
  follow :=0

  hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
  hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )

  hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)  ; buffer
  hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
  
  Gosub, Repaint
return 

toggle_follow: 
    follow := 1 - follow
  
    if follow = 1 
    {
        WinSet Region, 0-0  W%ww% H%wh% E  , PrintScreen
        toolbar := -32 ; height of window title
        GuiControl, Hide, zoom
    }
    else
    {
        WinSet Region,, PrintScreen
        toolbar :=toolbar_def
        GuiControl, Show, zoom
    }
Return

click_through:
    if follow = 1
    {
      Gui, Hide
      Send, {Click}
      SetTimer, Repaint , Off
      Sleep, 100
      Gui, Show
      SetTimer, Repaint, %delay%
    }
Return

Repaint: 

   CoordMode, Mouse, Screen                
   ;MouseGetPos, start_x, start_y             ;  position of mouse
   Gui, Submit, NoHide                       ; needed to read the dropdown and slidervalue
   GuiControl,, delay2 , delay %delay% ms
   WinGetPos, wx, wy, ww, wh , PrintScreen

   wh2 := wh - toolbar

    DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )  ; Halftone better quality with stretch
   
    DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,toolbar, Int,ww, Int,wh - toolbar
          , UInt,hdd_frame, Int
          , start_x-(ww / 2 / zoom)
          , Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020) ; SRCCOPY

   if follow = 1
     WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2 
   
  SetTimer, Repaint , %delay% 
Return

GuiClose:
handle_exit:
   DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp

Script of resources (need to use the focus on center of screen from this script, so that the magnifier will not follow mouse cursor)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; the specific (absolute) x, y to be magnified,
start_x:= 680, start_y:= 384
; the display of the magnified image x, y, w, h
xx:=380, yy:= 164, ww:=600, hh:=440

;ScreenMagnifier from holomind 
;https://autohotkey.com/board/topic/10660-screenmagnifier/
OnExit handle_exit

  Gui,  +AlwaysOnTop  +Owner +Resize +ToolWindow ; window for the dock
  Gui, Show, NoActivate w%ww% h%hh% x%xx% y%yy% , PrintScreen
  Gui, Add, DDL, vzoom   , 0.5|1|2||4|8|16 
  Gui, Add, Checkbox, y12 x150 vantialize, Antialize ?
  Gui, Add, Slider, vdelay x220 y0  Range1-200
  Gui, Add, Text, x340 y12 w80  vdelay2

  WinGet PrintScreenID, id  ,PrintScreen  ; 
  WinSet, Transparent , 254, PrintScreen

  ;retrieve the unique ID number (HWND/handle) of that window
  WinGet, PrintSourceID, id 

  hotkey , #x           , toggle_follow
  hotkey , +$LButton    , click_through

  toolbar_def:=35
  toolbar := toolbar_def
  follow :=0

  hdd_frame := DllCall( "GetDC", UInt, PrintSourceID )
  hdc_frame := DllCall( "GetDC", UInt, PrintScreenID )

  hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt,  hdc_frame)  ; buffer
  hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
  
  Gosub, Repaint
return 

toggle_follow: 
    follow := 1 - follow
  
    if follow = 1 
    {
        WinSet Region, 0-0  W%ww% H%wh% E  , PrintScreen
        toolbar := -32 ; height of window title
        GuiControl, Hide, zoom
    }
    else
    {
        WinSet Region,, PrintScreen
        toolbar :=toolbar_def
        GuiControl, Show, zoom
    }
Return

click_through:
    if follow = 1
    {
      Gui, Hide
      Send, {Click}
      SetTimer, Repaint , Off
      Sleep, 100
      Gui, Show
      SetTimer, Repaint, %delay%
    }
Return

Repaint: 

   CoordMode, Mouse, Screen                
   ;MouseGetPos, start_x, start_y             ;  position of mouse
   Gui, Submit, NoHide                       ; needed to read the dropdown and slidervalue
   GuiControl,, delay2 , delay %delay% ms
   WinGetPos, wx, wy, ww, wh , PrintScreen

   wh2 := wh - toolbar

    DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 * antialize )  ; Halftone better quality with stretch
   
    DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,toolbar, Int,ww, Int,wh - toolbar
          , UInt,hdd_frame, Int
          , start_x-(ww / 2 / zoom)
          , Int,start_y -( wh2 / 2/zoom), Int,ww / zoom, Int,wh2 / zoom ,UInt,0xCC0020) ; SRCCOPY

   if follow = 1
     WinMove, PrintScreen, ,start_x -ww/2 , start_y-wh/2 
   
  SetTimer, Repaint , %delay% 
Return

GuiClose:
handle_exit:
   DllCall("gdi32.dll\DeleteObject", UInt,hbm_buffer)
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
   DllCall("gdi32.dll\DeleteDC", UInt,hdc_buffer)
ExitApp
Thank you for reading

Hi how does it work?, How to enable it

Code: Select all

 hotkey , #x           , toggle_follow
  hotkey , +$LButton    , click_through
search for these fields to set the zoom key (x)

also you will have to set the resolution x,y - to fit your screen (at the time i had a 768p laptop which was an uncommon resolution, try coordinates for 1080p)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, taddypole, whoops and 212 guests