Hey, these codes and all the variations are really good
Can these scripts be made to toggle on and off with a keyboard hotkey?
And is it possible to get the same level of preciseness if this zoom is modified to be a loupe-type (zoom window where the pointer is)?
The code I'm trying to work on is holomind's variations on Trombonisto's double-crosshair code:
Code:
#NoEnv
SetBatchLines -1
CoordMode Mouse, Screen
OnExit #x
zoom = 8 ; initial magnification, 1..32
halfside = 128 ; circa halfside of the magnifier
part := halfside/zoom
Rz := Round(part)
R := Rz*zoom
LineMargin := 10
; GUI 2 shows the magnified image
Gui 2:+AlwaysOnTop -Caption +Resize +ToolWindow +E0x20
Gui 2:Show, % "w" 2*R+zoom+3 " h" 2*R+zoom+3 " 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)
;############# draw cross lines ###########################################
DrawCross( M_C , R_C, zoom_c, dc )
{
;specify the style, thickness and color of the cross lines
h_pen := DllCall( "gdi32.dll\CreatePen", "int", 0, "int", 1, "uint", 0x0000FF)
;select the correct pen into DC
DllCall( "gdi32.dll\SelectObject", "uint", dc, "uint", h_pen )
;update the current position to specified point - 1st horizontal
DllCall( "gdi32.dll\MoveToEx", "uint", dc, "int", M_C, "int", R_C, "uint", 0)
;draw a line from the current position up to, but not including, the specified point.
DllCall( "gdi32.dll\LineTo", "uint", dc, "int", R_C, "int", R_C)
; 2nd horizontal
DllCall( "gdi32.dll\MoveToEx", "uint", dc, "int", M_C, "int", R_C+zoom_c, "uint", 0)
DllCall( "gdi32.dll\LineTo", "uint", dc, "int", R_C, "int", R_C+zoom_c)
; 3rd horizontal
DllCall( "gdi32.dll\MoveToEx", "uint", dc, "int", R_C+zoom_c, "int", R_C, "uint", 0)
DllCall( "gdi32.dll\LineTo", "uint", dc, "int", 2*R_C+zoom_c-M_C, "int", R_C)
; 4th horizontal
DllCall( "gdi32.dll\MoveToEx", "uint", dc, "int", R_C+zoom_c, "int", R_C+zoom_c, "uint", 0)
DllCall( "gdi32.dll\LineTo", "uint", dc, "int", 2*R_C+zoom_c-M_C, "int", R_C+zoom_c)
; 1st vertical
DllCall( "gdi32.dll\MoveToEx", "uint", dc, "int", R_C, "int", M_C, "uint", 0)
DllCall( "gdi32.dll\LineTo", "uint", dc, "int", R_C, "int", R_C)
; 2nd vertical
DllCall( "gdi32.dll\MoveToEx", "uint", dc, "int", R_C+zoom_c, "int", M_C, "uint", 0)
DllCall( "gdi32.dll\LineTo", "uint", dc, "int", R_C+zoom_c, "int", R_C)
; 3rd vertical
DllCall( "gdi32.dll\MoveToEx", "uint", dc, "int", R_C, "int", R_C+zoom_c, "uint", 0)
DllCall( "gdi32.dll\LineTo", "uint", dc, "int", R_C, "int", 2*R_C+zoom_c-M_C)
; 4th vertical
DllCall( "gdi32.dll\MoveToEx", "uint", dc, "int", R_C+zoom_c, "int", R_C+zoom_c, "uint", 0)
DllCall( "gdi32.dll\LineTo", "uint", dc, "int", R_C+zoom_c, "int", 2*R_C+zoom_c-M_C)
}
SetTimer Repaint, 50 ; flow through
Repaint:
MouseGetPos x, y
xz := x-Rz
yz := y-Rz
DllCall("gdi32.dll\StretchBlt", UInt,hdc_frame, Int,0, Int,0, Int,2*R+zoom, Int,2*R+zoom
, UInt,hdd_frame, UInt,xz, UInt,yz, Int,2*Rz+1, Int,2*Rz+1, UInt,0xCC0020) ; SRCCOPY
DrawCross( LineMargin, R, zoom, hdc_frame )
; keep the frame outside the magnifier and precalculate wanted position
If (x < (2*R+zoom+8) and y < (2*R+zoom+8))
pos_new := (2*R+zoom+8)
Else
pos_new := 0
if ( pos_old <> pos_new ) ; only move if the real position of window needs to change
WinMove Magnifier,, ,pos_new
pos_old := pos_new ; store value for next loop
Return
#x::
DllCall("gdi32.dll\DeleteDC", UInt,hdc_frame )
DllCall("gdi32.dll\DeleteDC", UInt,hdd_frame )
ExitApp
#+::
^+WheelUp:: ; Ctrl+Shift+WheelUp to zoom in
#-::
^+WheelDown:: ; Ctrl+Shift+WheelUp to zoom out
If (zoom < 31 and ( A_ThisHotKey = "^+WheelUp" or A_ThisHotKey ="#+") )
zoom *= 1.189207115 ; sqrt(sqrt(2))
If (zoom > 1 and ( A_ThisHotKey = "^+WheelDown" or A_ThisHotKey = "#-"))
zoom /= 1.189207115
part := halfside/zoom ;new calculation of the magnified image
Rz := Round(part)
R := Rz*zoom
Gui 2:Show, % "w" 2*R+zoom+3 " h" 2*R+zoom+3 " x0 y0", Magnifier
TrayTip,,% "Zoom = " Round(100*zoom) "%"
Return
; Mouse slow down:
; The first parameter is always 0x71 (SPI_SETMOUSESPEED).
; The third parameter is the speed (range is 1-20, 10 is default).
F9::
if mouse_slow =
{
; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_hardware_information.asp
; http://www.autohotkey.com/forum/topic5264.html
DllCall("SystemParametersInfo", UInt, 0x70, UInt, 0, UIntP, mouse_speed_old, UInt, 0) ; important UintP (eg. return P(ointer) ?)
TrayTip,, your old mousespeed was %mouse_speed_old% , setting to 3
DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, 3, UInt, 0)
mouse_slow = 1
}
return
F9 up::
DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, 10, UInt, 0)
TrayTip,, restoring your mousespeed
mouse_slow =
return
;Mouse move one step with arrow keys
#Up::MouseMove, 0, -1, 0, R
#Down::MouseMove, 0, 1, 0, R
#Left::MouseMove, -1, 0, 0, R
#Right::MouseMove, 1, 0, 0, R