Universal Script 📌
949 Views
365 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
1.6M
2.1M
Bumped 6 hours ago
Key System

Script hub

#12 this week

Verified script badgeSnowy Hub 500+ Games & 25600+ Features

Script hub
269.2k
120.2k
Bumped 6 hours ago
Key System
Script hub
171.3k
1.4M
Bumped 9 hours ago
Key System
Script hub
16.7k
3.2k
Bumped 11 hours ago
Key System
Paid
Script hub
17.4k
88.6k
Bumped 11 hours ago
Universal Script 📌
852
44
Approved 12 hours ago
Universal Script 📌
2.0M
4.5k
Bumped 12 hours ago