Hi, I modified it, so if your mouse location is near screen border, the target window don't move ... and it was drawing above of the mouse, if you are in the lower screen area ...
I think, this is very useful, if you are a few meters away from your screen and want to cotrol anything with your remote controlled keyboard or mouse ...
PS.: I have only adapt the Magnifier function ...
Code:
/*
1)
Ctrl+Shift+Z starts new color zoomer, i.e., can have multiple balloon windows.
LeftClick picks the color.
Shift+LeftClick cancels the color zoomer.
Esc or RightClick close the active balloon window.
Shift+Esc or Shift+RightClick close the active balloon window, after copying the color to the clipboard.
Ctrl+Alt+Shift closes all the balloon windows.
Also may use Alt+Space, i.e. SysMenu.
2)
Ctrl+Shift+A starts the magnifier.
Ctrl+Shift+Q starts the magnifier, with Color-Inversion.
Esc closes the magnifier.
*/
#NoEnv
SetWinDelay, 10
CoordMode, Mouse
DetectHiddenWindows, On
^+A::Magnifier()
^+Q::Magnifier(1)
^+Z::Zoomer()
#IfWinActive, ahk_group Balloons
+Esc::
+RButton::
Clipboard := GetColor()
~RButton Up::
~Esc::GroupClose, Balloons, R
#IfWinActive
^!Shift::GroupClose, Balloons, A
Zoomer()
{
nZ := 6 ; Zoom Factor
nR := 108//2//nZ*nZ - 1 ; Rectangle of the Zoomer
VarSetCapacity(nColor,63)
nColor := A_Space
VarSetCapacity(ti, 40, 0)
ti := Chr(40)
DllCall("ntdll\RtlFillMemoryUlong", "Uint", &ti + 4, "Uint", 4, "Uint", 0x20)
DllCall("ntdll\RtlFillMemoryUlong", "Uint", &ti +36, "Uint", 4, "Uint", &nColor)
hWnd := DllCall("CreateWindowEx", "Uint", 0x08000008, "str", "tooltips_class32", "str", "", "Uint", 0x3, "int", 0, "int", 0, "int", 0, "int", 0, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0)
DllCall("SetClassLong", "Uint", hWnd, "int", -12, "int", DllCall("LoadCursor", "Uint", 0, "Uint", 32515))
SendMessage, 1028, 0, &ti,, ahk_id %hWnd%
SendMessage, 1041, 1, &ti,, ahk_id %hWnd%
SendMessage, 1036, 0, &ti,, ahk_id %hWnd%
hDC_SC := DllCall("GetDC", "Uint", 0)
hDC_TT := DllCall("GetDC", "Uint", hWnd)
Loop
{
MouseGetPos, xCursor, yCursor
DllCall("StretchBlt", "Uint", hDC_TT, "int", 0, "int", 0, "int", 2*nR, "int", 2*nR, "Uint", hDC_SC, "int", xCursor-nR//nZ, "int", yCursor-nR//nZ, "int", 2*nR//nZ, "int", 2*nR//nZ, "Uint", 0x00CC0020)
WinMove, ahk_id %hWnd%,, xCursor-(nR+1), yCursor-(nR+1), 2*(nR+1), 2*(nR+1) ; 1-pixel border
If GetKeyState("LButton")
Break
}
nColor := DllCall("GetPixel", "Uint", hDC_SC, "int", xCursor, "int", yCursor)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC_SC)
DllCall("ReleaseDC", "Uint", hWnd, "Uint", hDC_TT)
DllCall("SetClassLong", "Uint", hWnd, "int", -12, "int", DllCall("LoadCursor", "Uint", 0, "Uint", 32512))
If GetKeyState("Shift")
{
WinClose, ahk_id %hWnd%
Return
}
WinSet, ExStyle, -0x08000000, ahk_id %hWnd%
WinSet, Style, -0x00800000, ahk_id %hWnd%
WinSet, Style, +0x000800C0, ahk_id %hWnd%
SendMessage, 1042, 0, (xCursor & 0xFFFF) | (yCursor & 0xFFFF) << 16,, ahk_id %hWnd%
SendMessage, 1043, nColor, 0,, ahk_id %hWnd%
SendMessage, 1044,~nColor & 0xFFFFFF, 0,, ahk_id %hWnd%
pt := "Color @(" . xCursor . "," . yCursor . ")"
DllCall("wsprintf", "str", nColor, "str", " 0x%06X (#BBGGRR) ", "Uint", nColor, "Cdecl")
SendMessage, 1056, 0, &pt,, ahk_id %hWnd%
SendMessage, 1036, 0, &ti,, ahk_id %hWnd%
GroupAdd, Balloons, ahk_id %hWnd%
}
Magnifier(bInvert = False)
{
nZ := 3 ; Zoom Factor
nW := A_ScreenWidth // 5 //2//nZ ; Width of (small) Target Rectangle
nH := A_ScreenHeight// 5 //2//nZ ; Height of (small) Target Rectangle
screenVMiddle := A_ScreenHeight // 2
screenHMiddle := A_ScreenWidth // 2
CorOverMouse := (nH*nZ)+(nH) ; any value you like ;-)
CorBesideMouse:= (nW*nZ)+(nW) ; any value you like ;-)
ToolTip, %A_Space% ;Creates an always-on-top window anywhere on the screen
WinGet, hWnd, ID, ahk_class tooltips_class32 ;Retrieves the specified window's unique ID
WinClose, ahk_class SysShadow ;Comment it out to have the DropShadow
hDC_SC := DllCall("GetDC", "Uint", 0) ;retrieves a handle to a device context (DC) If the value is NULL, GetDC retrieves the DC for the entire screen
hDC_LW := DllCall("GetDC", "Uint", hWnd) ;retrieves a handle to a device context (DC) for the client area of a specified window
hDC_TT := DllCall("GetDC", "Uint", hWnd) ;retrieves a handle to a device context (DC) for the client area of a specified window
DllCall("SetStretchBltMode", "Uint", hDC_TT, "int", 4) ;sets the bitmap stretching mode
Loop
{
MouseGetPos, xCursor, yCursor
;------------------ Source Window ---------------------------
ySRC := yCursor-nH
if ((yCursor-nH) < 0)
ySRC := 0 ;upper border
if (yCursor+nH > A_ScreenHeight)
ySRC := A_ScreenHeight-2*nH ;lower border
xSRC := xCursor-nW
if ((xCursor-nW) < 0)
xSRC := 0 ;upper border
if (xCursor+nW > A_ScreenWidth)
xSRC := A_ScreenWidth-2*nW ;lower border
If bInvert
DllCall("BitBlt", "Uint", hDC_LW, "int", 0, "int", 0, "int", 2*nW, "int", 2*nH, "Uint", 0, "int", 0, "int", 0, "Uint", 0x00550009)
else
DllCall("BitBlt", "Uint", hDC_LW, "int", 0, "int", 0, "int", 2*nW, "int", 2*nH, "Uint", hDC_SC, "int", xSRC, "int", ySRC, "Uint", 0x40CC0020)
;------------------ Mouse Bitmap drawing ---------------------
yMaus := nH
if ((yCursor-nH) < 0)
yMaus := yCursor ;use coordinates for moving in upper area
if ((yCursor+nH) > A_ScreenHeight)
yMaus := yCursor-A_ScreenHeight+2*nH ;use coordinates for moving in lower area
xMaus := nW
if ((xCursor-nW) < 0)
xMaus := xCursor ;use coordinates for moving in upper area
if ((xCursor+nW) > A_ScreenWidth)
xMaus := xCursor-A_ScreenWidth+2*nW ;use coordinates for moving in lower area
Cursor(hDC_LW, xMaus, yMaus) ; Capture magnified mouse cursor.
;StretchBlt function copies a bitmap from a source rectangle into a destination rectangle
DllCall("StretchBlt", "Uint", hDC_TT, "int", 0, "int", 0, "int", 2*nW*nZ, "int", 2*nH*nZ, "Uint", hDC_LW, "int", 0, "int", 0, "int", 2*nW, "int", 2*nH, "Uint", 0x00CC0020)
; Cursor(hDC_TT, nW*nZ, nH*nZ) ; Capture un-magnified mouse cursor.
;------------------ Move destination Window -------------------
yPosOverWin := CorOverMouse ;correction value for Win above Mouse
if (yCursor>screenVMiddle)
yPosOverWin := -CorOverMouse
yPosWin := yCursor - (nH*nZ) + yPosOverWin
if (yPosWin-CorOverMouse < 0)
yPosWin := CorOverMouse
if ((yPosWin +(2*nH*nZ)+ CorOverMouse) > A_ScreenHeight)
yPosWin := A_ScreenHeight-(2*nH*nZ)-CorOverMouse
xPosBisideWin := CorBesideMouse ;correction value for Win beside Mouse
if (xCursor>screenHMiddle)
xPosBisideWin := -CorBesideMouse
xPosWin := xCursor - (nW*nZ) + xPosBisideWin
if ((xPosWin-CorBesideMouse) < 0)
xPosWin := CorBesideMouse
if ((xPosWin+(2*nW*nZ)+CorBesideMouse) > A_ScreenWidth)
xPosWin := A_ScreenWidth-(2*nW*nZ)-CorBesideMouse
WinMove, ahk_id %hWnd%,, xPosWin, yPosWin, 2*(nW*nZ+1), 2*(nH*nZ+1)
If GetKeyState("Esc")
Break
}
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC_SC)
DllCall("ReleaseDC", "Uint", hWnd, "Uint", hDC_LW)
DllCall("ReleaseDC", "Uint", hWnd, "Uint", hDC_TT)
WinClose, ahk_id %hWnd%
}
Cursor(hDC, xCenter, yCenter)
{
VarSetCapacity(mi, 20, 0) ;Enlarges a variable's holding capacity or frees its memory
mi := Chr(20) ;Returns the single character corresponding to the ASCII code indicated by Number
DllCall("GetCursorInfo", "Uint", &mi)
ptr := &mi + 4
bShow := *ptr++ | *ptr++ << 8 | *ptr++ << 16 | *ptr++ << 24
hCursor := *ptr++ | *ptr++ << 8 | *ptr++ << 16 | *ptr++ << 24
DllCall("GetIconInfo", "Uint", hCursor, "Uint", &mi)
ptr := &mi + 4
xHotspot := *ptr++ | *ptr++ << 8 | *ptr++ << 16 | *ptr++ << 24
yHotspot := *ptr++ | *ptr++ << 8 | *ptr++ << 16 | *ptr++ << 24
hBMMask := *ptr++ | *ptr++ << 8 | *ptr++ << 16 | *ptr++ << 24
hBMColor := *ptr++ | *ptr++ << 8 | *ptr++ << 16 | *ptr++ << 24
DllCall("DeleteObject", "Uint", hBMMask)
DllCall("DeleteObject", "Uint", hBMColor)
If bShow
DllCall("DrawIcon", "Uint", hDC, "int", xCenter - xHotspot, "int", yCenter - yHotspot, "Uint", hCursor)
}
GetColor()
{
VarSetCapacity(nColor, 8)
SendMessage, 1046, 0, 0,, A
DllCall("wsprintf", "str", nColor, "str", "0x%06X", "Uint", ErrorLevel, "Cdecl")
Return nColor
}