
949 Views
365 Executions
Fix MouseLock for PC Control for delta
Universal Script 📌 7 months ago
Please login to perform these actions:Does it work?
No reports yetNo reports yet. Tried it? Be the first to say.
Also noticed:
Description
Fix MouseLock for Delta UI bug. I hope it is you want.
local VirtualInputManager = game:GetService("VirtualInputManager")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
-- 【常量预存】
local MOUSE_BUTTON_2 = 1
local isHolding = false
-- 【环境检测函数】
-- 如果设备支持键盘且不支持纯触摸,或者有鼠标,则判定为PC环境
local function IsDesktopEnvironment()
-- TouchEnabled 虽然在带触摸屏的电脑上也是 true,
-- 但 KeyboardEnabled 只有在有实体/虚拟键盘映射时才为 true
-- 最稳妥的判断:有鼠标且有键盘
return UserInputService.KeyboardEnabled and UserInputService.MouseEnabled
end
-- 【中心点动态缓存】
local cx, cy = 0, 0
local function updateCache()
local size = workspace.CurrentCamera.ViewportSize
cx, cy = size.X / 2, size.Y / 2
end
updateCache()
workspace.CurrentCamera:GetPropertyChangedSignal("ViewportSize"):Connect(updateCache)
-- 【强制接管函数】
local function ForceTakeover()
if not isHolding then
VirtualInputManager:SendMouseButtonEvent(cx, cy, MOUSE_BUTTON_2, false, game, 0)
VirtualInputManager:SendMouseButtonEvent(cx, cy, MOUSE_BUTTON_2, true, game, 0)
isHolding = true
end
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end
local function ForceRelease()
if isHolding then
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
VirtualInputManager:SendMouseButtonEvent(cx, cy, MOUSE_BUTTON_2, false, game, 0)
Comments
0Log in to join the conversation. Login
No comments yet. Be the first!








