local function P(P,N)if N then return end if P.UserInputType==Enum.UserInputType.Keyboard and(P.KeyCode==Enum.KeyCode.LeftShift or P.KeyCode==Enum.KeyCode.RightShift)then mouseLockSwitchFunc()end end local function N()IsShiftLockMode=isShiftLockMode()if IsShiftLockMode then if ScreenGui then ScreenGui.Parent=PlayerGui end if IsShiftLocked then Mouse.Icon=SHIFT_LOCK_CURSOR ShiftLockController.OnShiftLockToggled:Fire()end if not IsActionBound then InputCn=UserInputService.InputBegan:connect(P)IsActionBound=true end end end GameSettings.Changed:connect(function(P)if P=="\067\111\110\116\114\111\108\077\111\100\101"then if GameSettings.ControlMode==Enum.ControlMode.MouseLockSwitch then N()else disableShiftLock()end elseif P=="\067\111\109\112\117\116\101\114\077\111\118\101\109\101\110\116\077\111\100\101"then if GameSettings.ComputerMovementMode==Enum.ComputerMovementMode.ClickToMove then disableShiftLock()else N()end end end)LocalPlayer.Changed:connect(function(P)if P=="\068\101\118\069\110\097\098\108\101\077\111\117\115\101\076\111\099\107"then if LocalPlayer.DevEnableMouseLock then N()else disableShiftLock()end elseif P=="\068\101\118\067\111\109\112\117\116\101\114\077\111\118\101\109\101\110\116\077\111\100\101"then if LocalPlayer.DevComputerMovementMode==Enum.DevComputerMovementMode.ClickToMove or LocalPlayer.DevComputerMovementMode==Enum.DevComputerMovementMode.Scriptable then disableShiftLock()else N()end end end)LocalPlayer.CharacterAdded:connect(function(P)if not UserInputService.TouchEnabled then initialize()end end)
-- TODO: Remove when we figure out ContextActionService without sinking keys
local function onShiftInputBegan(inputObject, isProcessed)
	if isProcessed then
		return
	end
	if
		inputObject.UserInputType == Enum.UserInputType.Keyboard
		and (inputObject.KeyCode == Enum.KeyCode.LeftShift or inputObject.KeyCode == Enum.KeyCode.RightShift)
	then
		--
		mouseLockSwitchFunc()
	end
end

local function enableShiftLock()
	IsShiftLockMode = isShiftLockMode()
	if IsShiftLockMode then
		if ScreenGui then
			ScreenGui.Parent = PlayerGui
		end
		if IsShiftLocked then
			Mouse.Icon = SHIFT_LOCK_CURSOR
			ShiftLockController.OnShiftLockToggled:Fire()
		end
		if not IsActionBound then
			InputCn = UserInputService.InputBegan:connect(onShiftInputBegan)
			IsActionBound = true
		end
	end
end

GameSettings.Changed:connect(function(property)
	if property == "ControlMode" then
		if GameSettings.ControlMode == Enum.ControlMode.MouseLockSwitch then
			enableShiftLock()
		else
			disableShiftLock()
		end
	elseif property == "ComputerMovementMode" then
		if GameSettings.ComputerMovementMode == Enum.ComputerMovementMode.ClickToMove then
			disableShiftLock()
		else
			enableShiftLock()
		end
	end
end)

LocalPlayer.Changed:connect(function(property)
	if property == "DevEnableMouseLock" then
		if LocalPlayer.DevEnableMouseLock then
			enableShiftLock()
		else
			disableShiftLock()
		end
	elseif property == "DevComputerMovementMode" then
		if
			LocalPlayer.DevComputerMovementMode == Enum.DevComputerMovementMode.ClickToMove
			or LocalPlayer.DevComputerMovementMode == Enum.DevComputerMovementMode.Scriptable
		then
			--
			disableShiftLock()
		else
			enableShiftLock()
		end
	end
end)

LocalPlayer.CharacterAdded:connect(function(character)
	-- we need to recreate guis on character load
	if not UserInputService.TouchEnabled then
		initialize()
	end
end)
