-- =========================================================================== -- KeyProbe (CLIENTE) - prueba para decidir si se puede hacer una casilla de texto -- (text area) dentro del juego, para escribir saludos largos. -- -- Tecla F11: abre / cierra una ventana de prueba. Mientras esta abierta, escribe cualquier cosa: -- * La ventana muestra el texto que se arma y los ultimos codigos de tecla recibidos. -- * Se prueban SetLockInterfaces / LockPlayerWalk (bloquear el juego mientras escribes). -- * Ctrl+V prueba pegar desde el portapapeles (PowerShell oculto, como la radio). -- * Esc o F11 cierra. -- Todo lo que pase se anota en KeyProbe.txt (carpeta del juego). Mandamelo al terminar. -- -- Ubicacion: Data\Custom\Script\Scripts\KeyProbe\KeyProbe.lua (requirefolder('Scripts\\KeyProbe')) -- Imagenes: las rk_*.ozt del ranking (ya instaladas). -- Es SOLO una prueba: se borra despues. -- =========================================================================== local OPEN_KEY = Keys.F11 or 122 local LOG_FILE = "KeyProbe.txt" local IMG = { tl = 40180, tm = 40181, tr = 40182, ml = 40183, mm = 40184, mr = 40185, bl = 40186, bm = 40187, br = 40188 } local IMG_FILES = { [40180] = "rk_tl", [40181] = "rk_tm", [40182] = "rk_tr", [40183] = "rk_ml", [40184] = "rk_mm", [40185] = "rk_mr", [40186] = "rk_bl", [40187] = "rk_bm", [40188] = "rk_br" } local S = { open = false, buf = "", events = {}, loaded = false, lockMsg = "", clip = "", clipAt = 0, clipWait = false, nEv = 0 } BridgeFunctionAttach('KeyboardEvent', 'KeyProbe_Key') BridgeFunctionAttach('MainInterfaceProcThread', 'KeyProbe_Draw') BridgeFunctionAttach('UpdateMouseEvent', 'KeyProbe_Mouse') BridgeFunctionAttach('UpdateKeyEvent', 'KeyProbe_UpdateKey') local function Log(msg) local ok, f = pcall(io.open, LOG_FILE, "a") if ok and f then f:write(os.date("%H:%M:%S "), msg, "\n"); f:close() end end local function Try(name, ...) local fn = _G[name] if type(fn) ~= "function" then return name .. ": no existe" end local ok, a, b = pcall(fn, ...) if ok then return string.format("%s(%s) -> ok %s %s", name, table.concat({ ... }, ","), tostring(a), tostring(b)) end return string.format("%s(%s) -> ERROR %s", name, table.concat({ ... }, ","), tostring(a)) end local function Held(code) local ok, v = pcall(CheckRepeatKey, code) if ok and (v == 1 or v == true) then return true end local ok2, v2 = pcall(CheckPressedKey, code) return ok2 and (v2 == 1 or v2 == true) end -- Mapa de teclas -> caracter. Supone teclado "Espanol Latinoamerica"; la prueba muestra si acierta. local SHIFT_DIGITS = { [0] = "=", "!", "\"", "#", "$", "%", "&", "/", "(", ")" } local function CharFor(code, shift) if code >= 65 and code <= 90 then local c = string.char(code) return shift and c or string.lower(c) end if code >= 48 and code <= 57 then local d = code - 48 return shift and SHIFT_DIGITS[d] or tostring(d) end if code >= 96 and code <= 105 then return tostring(code - 96) end if code == 32 then return " " end if code == 190 then return shift and ":" or "." end if code == 188 then return shift and ";" or "," end if code == 189 then return shift and "_" or "-" end if code == 187 then return shift and "*" or "+" end if code == 219 then return shift and "?" or "'" end if code == 192 then return shift and "N" or "n" end -- n con tilde en este teclado: se guarda como n return nil end local function Open() if GetMainScene() ~= 5 then return end S.open, S.buf, S.events, S.nEv = true, "", {}, 0 Log("=== abierto (escena " .. tostring(GetMainScene()) .. ") ===") local r1 = Try("SetLockInterfaces") local r2 = Try("LockPlayerWalk", 1) S.lockMsg = r1 .. " | " .. r2 Log(r1); Log(r2) end local function Close() S.open = false local r1 = Try("SetUnlockInterfaces") local r2 = Try("LockPlayerWalk", 0) Log(r1); Log(r2); Log("=== cerrado. texto final (" .. #S.buf .. "): " .. S.buf) end local function StartClipboard() pcall(os.remove, "KeyProbe_clip.txt") local ok, f = pcall(io.open, "KeyProbe_clip.ps1", "w") if not ok or not f then Log("no pude escribir KeyProbe_clip.ps1"); return end f:write("$t = Get-Clipboard -Raw\r\n$t = [string]$t\r\n[IO.File]::WriteAllText((Join-Path $PSScriptRoot 'KeyProbe_clip.txt'), $t, [Text.Encoding]::ASCII)\r\n") f:close() local ok2, h = pcall(io.popen, 'cmd /c start "" /min powershell -NoProfile -Sta -ExecutionPolicy Bypass -WindowStyle Hidden -File KeyProbe_clip.ps1') S.h = ok2 and h or nil S.clipWait, S.clipAt, S.clip = true, os.clock(), "(leyendo...)" Log("Ctrl+V: pidiendo portapapeles") end local function PollClipboard() if not S.clipWait then return end local ok, f = pcall(io.open, "KeyProbe_clip.txt", "r") if ok and f then local t = f:read("*a") or "" f:close() S.clipWait = false local clean = t:gsub("[^\32-\126]", " ") S.clip = string.format("%d letras: %s", #t, string.sub(clean, 1, 40)) Log("portapapeles: " .. #t .. " letras en " .. string.format("%.2f", os.clock() - S.clipAt) .. " s: " .. string.sub(clean, 1, 80)) S.buf = string.sub(S.buf .. clean, 1, 220) elseif os.clock() - S.clipAt > 6 then S.clipWait, S.clip = false, "(sin respuesta en 6 s)" Log("portapapeles: sin respuesta") end end function KeyProbe_Key(key) if CheckWindowOpen(UIChatWindow) == 1 then return end if key == OPEN_KEY then if S.open then Close() else Open() end return end if not S.open then return end S.nEv = S.nEv + 1 local code = key & 0xFFFF local mods = key & 0xFFFF0000 local shift = (mods & 65536) ~= 0 or Held(Keys.ShiftKey) or Held(Keys.LShiftKey) or Held(Keys.RShiftKey) local ctrl = (mods & 131072) ~= 0 or Held(Keys.ControlKey) or Held(Keys.LControlKey) or Held(Keys.RControlKey) local line = string.format("#%d raw=%d code=%d mods=0x%X shift=%s ctrl=%s", S.nEv, key, code, mods, tostring(shift), tostring(ctrl)) Log(line) table.insert(S.events, 1, string.format("%d (code %d)%s%s", key, code, shift and " +Shift" or "", ctrl and " +Ctrl" or "")) if #S.events > 9 then table.remove(S.events) end if code == Keys.Escape then Close(); return end if code == Keys.Back then S.buf = string.sub(S.buf, 1, -2); return end if code == Keys.Return then S.buf = S.buf .. "\n"; return end if ctrl and code == Keys.V then StartClipboard(); return end local c = CharFor(code, shift) if c and #S.buf < 220 then S.buf = S.buf .. c end end function KeyProbe_Mouse() end function KeyProbe_UpdateKey() if S.open then pcall(DisableClickClient) end end local function Img(id, x, y, w, h) RenderImage2(id, x, y, w, h, 0.0, 0.0, 1.0, 1.0, 1, 1, 1.0) end local function Frame(x, y, w, h) local c = 8 Img(IMG.tl, x, y, c, c); Img(IMG.tm, x + c, y, w - 2 * c, c); Img(IMG.tr, x + w - c, y, c, c) Img(IMG.ml, x, y + c, c, h - 2 * c); Img(IMG.mm, x + c, y + c, w - 2 * c, h - 2 * c); Img(IMG.mr, x + w - c, y + c, c, h - 2 * c) Img(IMG.bl, x, y + h - c, c, c); Img(IMG.bm, x + c, y + h - c, w - 2 * c, c); Img(IMG.br, x + w - c, y + h - c, c, c) end local function Text(x, y, s, w, align, r, g, b) SetTextColor(r, g, b, 255); RenderText5(x, y, s, w, align) end local function Wrap(s, n) local out = {} for para in (s .. "\n"):gmatch("(.-)\n") do if para == "" then out[#out + 1] = "" end while #para > 0 do out[#out + 1] = string.sub(para, 1, n); para = string.sub(para, n + 1) end end return out end function KeyProbe_Draw() if not S.loaded then S.loaded = true for id, f in pairs(IMG_FILES) do LoadBitmap("Custom\\ScriptImages\\" .. f .. ".tga", id) end end PollClipboard() if not S.open then return end local x, y, w, h = 20, 60, 300, 300 Frame(x, y, w, h) SetFontType(1); SetTextBg(0, 0, 0, 0) Text(x, y + 10, "PRUEBA DE CASILLA DE TEXTO", w, ALIGN_CENTER, 255, 215, 90) Text(x, y + 24, "Escribe: letras, numeros, espacio, . , - Enter Borrar | Ctrl+V pega | Esc cierra", w, ALIGN_CENTER, 170, 170, 180) local cur = (math.floor(os.clock() * 2) % 2 == 0) and "|" or " " local lines = Wrap(S.buf .. cur, 40) local ty = y + 44 for i = math.max(1, #lines - 5), #lines do Text(x + 12, ty, lines[i], w - 24, ALIGN_LEFT, 255, 255, 255) ty = ty + 14 end Text(x + 12, y + 132, string.format("%d / 220 letras", #S.buf), w - 24, ALIGN_LEFT, 160, 150, 120) Text(x + 12, y + 150, "Ultimas teclas recibidas:", w - 24, ALIGN_LEFT, 200, 200, 120) for i, e in ipairs(S.events) do Text(x + 12, y + 150 + i * 12, e, w - 24, ALIGN_LEFT, 235, 235, 240) end Text(x + 12, y + h - 30, "Portapapeles: " .. S.clip, w - 24, ALIGN_LEFT, 130, 255, 150) Text(x + 12, y + h - 18, "Mira si el juego reacciona a las teclas (skills, menus, caminar).", w - 24, ALIGN_LEFT, 255, 215, 90) end Console(1, "[KeyProbe] cargado - F11 abre la prueba")