I want to do things like select objects in the explorer, type commands, edit properties, etc. but this is impossible or very difficult to do when the mouse is locked because focusing any part of studio will force the mouse to be locked to the game’s viewport, and doing anything that unlocks the mouse will unlock it in the viewport too.
4 Likes
game:GetService("UserInputService").InputBegan:Connect(function(obj)
if obj.KeyCode == Enum.KeyCode.LeftControl then -- unlock mouse keybind
game:GetService("UserInputService").MouseIconEnabled = not game:GetService("UserInputService").MouseIconEnabled
end
if game:GetService("UserInputService").MouseBehavior == Enum.MouseBehavior.Default then
game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
else
game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
end
end)
use the code above in a localscript to unlock/lock the mouse by pressing left control
It’s always possible to manually add things to unlock the mouse, but we shouldn’t need to do that, and it doesn’t solve all use cases anyway. It is often still desirable to keep the mouse in the locked state in the game itself e.g. you are trying to debug things that happen only while the mouse is locked.