Здравствуйте, гость ( Вход | Регистрация )

> Лупа, Готовый скрипт
cirus
сообщение 3.4.2020, 14:56
Сообщение #1


**********

Elder
Сообщений: 3.480
Регистрация: 18.8.2014
Группа: Пользователи
Наличность: 26420
Пользователь №: 16.971
Возраст: 29



Пилот 2.41. Запускать от админа. Возможно мерцание, т. к. изображение выводится на экран, а не на окно.
Лупа
Код
--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
Пользователь в офлайнеDelete PostОтправить личное сообщение
Вернуться в начало страницы
+Ответить с цитированием данного сообщения

Сообщений в этой теме
cirus   Лупа   3.4.2020, 14:56
FREEON   возможности lua не перестают удивлять...   3.4.2020, 18:54
DarkMaster   Сам писал?   27.9.2020, 15:37
cirus   Да.   27.9.2020, 20:16
DarkMaster   Крут. А в оверлей реально выводить?   27.9.2020, 21:15
cirus   Не знаю. Можно в окно, которое поверх всех.   27.9.2020, 21:26
DarkMaster   При фул скрине будут проблемы. По этому я про ове...   28.9.2020, 0:08
DarkMaster   Повыкидывал вейты, все обработки кроме лупы - морг...   29.3.2022, 18:21
cirus   --lua local ffi = require("ffi") l...   30.3.2022, 12:14
DarkMaster   Не знаю почему, но у первой версии лупы скорость ...   30.3.2022, 12:22
cirus   Не помню, код давно написан. Можно nil передавать...   30.3.2022, 12:31
DarkMaster   Не хочется наглеть, но тем не менее) А borderless ...   30.3.2022, 13:46
cirus   local WS_POPUP = 0x80000000 main_window = ffi.C.C...   30.3.2022, 14:01
DarkMaster   Без рамок завершить не представляется возможным вв...   30.3.2022, 14:22
cirus   Добавил хоткей для закрытия окна. Ctrl + Shift + Z...   30.3.2022, 14:53
DarkMaster   Шуршит шикарно. Последний вопрос :) Как кастом при...   30.3.2022, 15:16
DarkMaster   Размер окна вынесен в шапку скрипта, туда же возмо...   30.3.2022, 17:33
Cockney   tonumber(ffi.cast('void*', main_window)) ...   30.3.2022, 18:35
DarkMaster   так только через два каста можно.   30.3.2022, 22:27


Ответить в эту темуОткрыть новую тему
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 

- Текстовая версия | Версия для КПК Сейчас: 3.9.2025, 12:14
Designed by Nickostyle