Universal Script 📌
972 Views
499 Executions

Fix MouseLock for PC Control for delta

Universal Script 📌
7 months ago
Get an executor
Please login to perform these actions:

Does it work?

No reports yet

No reports yet. Tried it? Be the first to say.

Also noticed:

Description

Fix MouseLock for Delta UI bug. I hope it is you want.

View Raw
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

0
Log in to join the conversation. Login
No comments yet. Be the first!

Tags

More universal scripts

See all
Script hub
3.0M
18.5M
Bumped 3 hours ago

Script hub

Hall of Fame #1

KeylessVerified script badgeYARHM Hub KEYLESS 2026

Script hub
119.5k
193.9k
Bumped 8 hours ago
Key System
Script hub
180.9k
1.8M
Bumped 8 hours ago
Key System
Universal Script 📌
1.2k
2.6k
Bumped 9 hours ago
Script hub
60.2k
244.1k
Bumped 9 hours ago
Key System
Universal Script 📌
6.2k
53.5k
Bumped 11 hours ago