Disabling I and O keys to zoom the camera in and out

I’m trying to create a key bind where upon pressing the I key it changes changes the view of the camera. As you may know, pressing I actually zooms the camera in, which is something I thought I can override by just changing the camera directly, but after returning the camera back to the character, it zooms in and sometimes spazzes out. Upon changing the key bind to a key besides I, this issue is resolved, but I still want to do this without changing the originally intended key bind.

How would I go about disabling the I and O keys to adjust camera zoom?

1 Like

The binding that’s responsible for zooming in/out with the keyboard is “BaseCameraKeyboardZoom”, which you can see in this screenshot:

You can disable it like this:

local ActionS = game:GetService("ContextActionService")
ActionS:UnbindAction("BaseCameraKeyboardZoom")

It won’t work if it runs right away when the player joins, you’ll have to either wait() a couple of seconds or at other points during the game, e.g. on CharacterAdded or when your own camera script is setting up.

EDIT: Apparently this broke after a while. There’s no longer any default actions bound to BaseCameraKeyboardZoom. Annoyingly the new action is called RbxCameraKeypress and covers both zooming with I and O, as well as panning with Left and Right :confused:

You can do this to unbind all 4 keys:

for _ = 1, 2 do
	while true do
		local info = ActionS:GetBoundActionInfo("RbxCameraKeypress")
		if info and info.inputTypes then
			ActionS:UnbindAction("RbxCameraKeypress")
			break
		else
			wait()
		end
	end
end

Trying 2 times works for me in Studio, increase it to a larger number (or even math.huge) if it isn’t enough.

A much better way is this:

local ActionS = game:GetService("ContextActionService")
ActionS:BindActionAtPriority("do nothing", function() return Enum.ContextActionResult.Sink end, false, 3000, Enum.KeyCode.I, Enum.KeyCode.O)

You could also bind any action you actually want to these keys, just make sure you do it at a priority level > default (2000).

18 Likes

Hey there! Thank you for updating your solution, I really appreciate it! Im not an expert at coding yet, so I was wondering if you could explain what this does:

ActionS:BindActionAtPriority("do nothing", function() return Enum.ContextActionResult.Sink end, false, 3000, Enum.KeyCode.I, Enum.KeyCode.O)

Thanks in Advanced!

1 Like

You can read more about it here:

https://developer.roblox.com/en-us/api-reference/function/ContextActionService/BindActionAtPriority

1 Like

Hey again! I tried using the script, but it totally disables the “I” and “O” function for me, I’m trying to disable the “I” and “O” zoom keybinds so I can use “I” to open the inventory, and yes I did try if my “Press “I” to open the inventory” script works by using “P”.

P.S. I’m pretty new to having access to post stuff here in dev forum, so idk if it’s appropriate to post my issue in someone else’s topic.

Just replace his “do nothing” function, with your function which opens your inventory.

I think in this case there would be the need to do a split between the action keys, since the “do nothing” action would apply to both the “I” and “O” keys. (You can easily notice that by reading the code)
Alternatively, he could use the UserInputService for the inventory key. (Yeah, UIS not responding to “I” and “O” inputs is a Studio only bug lol)

1 Like