--lua
local ffi = require("ffi")
local user = ffi.load('User32.dll')
local gdi = ffi.load('Gdi32.dll')
ffi.cdef[[
struct HDC__ { int unused; }; typedef struct HDC__ *HDC;
struct HWND__ { int unused; }; typedef struct HWND__ *HWND;
struct HBRUSH__ { int unused; }; typedef struct HBRUSH__ *HBRUSH;
struct HBITMAP__ { int unused; }; typedef struct HBITMAP__ *HBITMAP;
struct HPEN__ { int unused; }; typedef struct HPEN__ *HPEN;
typedef struct tagRECT{ long left; long top; long right; long bottom;}RECT;
typedef struct tagPOINT {long x; long y;} POINT, *PPOINT, *NPPOINT, *LPPOINT;
typedef struct tagLOGBRUSH {unsigned long lbStyle;unsigned long lbColor; unsigned long lbHatch;} LOGBRUSH, *PLOGBRUSH, *NPLOGBRUSH, *LPLOGBRUSH;
typedef void *HGDIOBJ;
typedef void *PVOID;
short GetAsyncKeyState(int vKey);
HDC GetDC(HWND hWnd);
HDC CreateCompatibleDC(HDC hdc);
HBITMAP CreateCompatibleBitmap(HDC hdc, int cx, int cy);
HGDIOBJ SelectObject(HDC hdc, HGDIOBJ h);
HPEN CreatePen(int iStyle, int cWidth, unsigned long color);
HPEN ExtCreatePen(unsigned long iPenStyle, unsigned long cWidth, const LOGBRUSH *plbrush, unsigned long cStyle, const unsigned long *pstyle);
HBRUSH CreateSolidBrush(unsigned long color);
bool StretchBlt(HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdcSrc, int xSrc, int ySrc, int wSrc, int hSrc, unsigned long rop);
bool BitBlt(HDC hdc, int x, int y, int cx, int cy, HDC hdcSrc, int x1, int y1, unsigned long rop);
bool DeleteObject(HGDIOBJ ho);
bool LineTo(HDC hdc, int x, int y);
bool MoveToEx(HDC hdc, int x, int y, LPPOINT lppt);
bool SystemParametersInfoA(unsigned int uiAction, unsigned int uiParam, PVOID pvParam, unsigned int fWinIni);
int FillRect(HDC hDC, const RECT *lprc, HBRUSH hbr);
]]
local SRCCOPY = 13369376
local PS_USERSTYLE = 7
local PS_SOLID = 0
local BS_SOLID = 0
local COLOR_BLACK = 0
local COLOR_WHITE = 16777215
local LOGBRUSH = ffi.new('LOGBRUSH', {BS_SOLID, COLOR_WHITE, 0})
local pstyle = ffi.new('int[2]', {1, 1})
local hdc = user.GetDC(ffi.cast('HWND', 0))
local Comp = gdi.CreateCompatibleDC(hdc)
local Comp2 = gdi.CreateCompatibleDC(hdc)
local bitmap = gdi.CreateCompatibleBitmap(hdc, 200, 200)
local bitmap2 = gdi.CreateCompatibleBitmap(hdc, 200, 200)
gdi.SelectObject(Comp, bitmap)
gdi.SelectObject(Comp2, bitmap2)
local Brush = gdi.CreateSolidBrush(COLOR_WHITE)
local Pen_black = gdi.CreatePen(PS_SOLID, 1, COLOR_BLACK)
local Pen = gdi.ExtCreatePen(PS_USERSTYLE, 1, LOGBRUSH, 2, pstyle)
local rect = ffi.new('RECT', {0, 0, 200, 200})
local mouse_speed, zoom
function lupa()
local mouseX, mouseY = mouse_pos ('abs')
user.FillRect(Comp, rect, Brush)
local pos = math.floor(100 / zoom)
local wSrc = math.floor(200 / zoom)
local hSrc = math.floor(200 / zoom)
gdi.StretchBlt(Comp, 0, 0, wSrc * zoom, hSrc * zoom, hdc, mouseX - pos, mouseY - pos, wSrc, hSrc, SRCCOPY)
gdi.BitBlt(Comp2, 0, 0, 200, 200, Comp, 0, 0, SRCCOPY)
local delta = math.floor(pos * zoom + zoom / 2)
local oldPen = gdi.SelectObject(Comp2, Pen_black)
gdi.MoveToEx(Comp2, 0, delta, ffi.cast('LPPOINT', 0))
gdi.LineTo(Comp2, 200, delta)
gdi.MoveToEx(Comp2, delta, 0, ffi.cast('LPPOINT', 0))
gdi.LineTo(Comp2,delta, 200)
gdi.SelectObject(Comp2, oldPen)
oldPen = gdi.SelectObject(Comp2, Pen)
gdi.MoveToEx(Comp2, 0, delta, ffi.cast('LPPOINT', 0))
gdi.LineTo(Comp2, 200, delta)
gdi.MoveToEx(Comp2, delta, 0, ffi.cast('LPPOINT', 0))
gdi.LineTo(Comp2, delta, 200)
gdi.SelectObject(Comp2, oldPen)
gdi.BitBlt(hdc, 0, 0, 200, 200, Comp2, 0, 0, SRCCOPY)
end
function zoom_control()
if user.GetAsyncKeyState(90) ~= 0 then -- если нажата клавиша Z
while user.GetAsyncKeyState(90) ~= 0 do wait(1) end
if zoom > 1 then zoom = zoom - 1 end
end
if user.GetAsyncKeyState(88) ~= 0 then -- если нажата клавиша X
while user.GetAsyncKeyState(88) ~= 0 do wait(1) end
if zoom < 20 then zoom = zoom + 1 end
end
end
function SETMOUSESPEED(speed)
local SPI_SETMOUSESPEED = 113
local mouse_speed = ffi.new('int[1]', speed)
user.SystemParametersInfoA(SPI_SETMOUSESPEED, 0, ffi.cast('PVOID', mouse_speed[0]), 0)
end
function GETMOUSESPEED()
local SPI_GETMOUSESPEED = 112
local mouse_speed = ffi.new('int[1]')
user.SystemParametersInfoA(SPI_GETMOUSESPEED, 0, mouse_speed, 0)
return mouse_speed[0]
end
function mouse_control()
if user.GetAsyncKeyState(67) ~= 0 then -- если нажата клавиша C
while user.GetAsyncKeyState(67) ~= 0 do wait(1) end
if GETMOUSESPEED() > 1 then
mouse_speed = mouse_speed - 1
SETMOUSESPEED(mouse_speed)
end
end
if user.GetAsyncKeyState(86) ~= 0 then -- если нажата клавиша V
while user.GetAsyncKeyState(86) ~= 0 do wait(1) end
if GETMOUSESPEED() < 20 then
mouse_speed = mouse_speed + 1
SETMOUSESPEED(mouse_speed)
end
end
end
function hint_()
local s = 'Изменение масштаба клавиши Z и X' .. '\r\n' .. 'Скорость курсора клавиши C и V' .. '\r\n'
hint (s .. 'Увеличение: x' .. zoom .. '\r\n' .. 'Скорость курсора: ' .. mouse_speed)
end
mouse_speed = GETMOUSESPEED()
zoom = 10 -- во сколько раз увеличить, начальное значение от 1 до 20
while true do
lupa() -- вывод изображения
zoom_control() -- изменение масштаба вывода
mouse_control() -- изменение скорости курсора
hint_() -- вывод подсказки
wait(1)
end