Enum.KeyCode.O not recognized by ContextActionService

Reproduction Steps

  1. Run this on a LocalScript:
local ContextActionService  = game:GetService("ContextActionService")
local function OpenTextBox(ActionName, InputState, InputObject)
	print(InputObject.KeyCode)
end

ContextActionService:BindAction("OpenTextBox", OpenTextBox, false, Enum.KeyCode.A, Enum.KeyCode.O, Enum.KeyCode.K) 
  1. Press keys A, O, and K

Expected Behavior
All keys might be recognized.


Actual Behavior
Enum.KeyCode.O is not being recognized

Issue Area: Engine
Issue Type: Other
Impact: High
Frequency: Constantly

1 Like

Unfortunately, by default, keys ‘I’ and ‘O’ are both used for Roblox core features for zooming the player’s camera in and out. You are going to have to either use different keys, or you can suggest the following solution:

local UserInputService = game:GetService("UserInputService")
local keyOHeld = UserInputService:IsKeyDown(Enum.KeyCode.O) // Returns a boolean value of true or false

So you are saying that I can’t intercept keys I and O with ContextActionService.BindAction?

Realistically no, however if you wanted to really remove the Roblox implemented feature, you could try and find the name of the action used for zooming in ‘O’ and use the :UnBind() method within the following documentation:
https://developer.roblox.com/en-us/api-reference/function/ContextActionService/UnbindAction

niknj_113881

For anyone that wants to do that, it is here. But be warned, this will also disable the left and right arrow keys. If you wish to keep the left/right arrow keys and unbind I and O, you can put this in your StarterPlayerScripts:
PlayerModule.rbxm (114.8 KB)

It’s just the default player module with I and O removed.

2 Likes

Thanks, but I didn’t understand your suggestion.
I changed my code to:

ContextActionService:BindActionAtPriority("OpenTextBox", OpenTextBox, false, 99, 
	Enum.KeyCode.I, Enum.KeyCode.O, Enum.KeyCode.K)´

… but still have no effect on keys I and O…

You can use BindActionAtPriority with a very high priority to override the existing built-in keybind, however, you should refrain from overriding default keybinds since it may be confusing to users.

I’d recommend always using BindActionAtPriority over BindAction.

1 Like

99 is a super low value.

See here for some defaults that some of the core scripts use: ContextActionPriority | Roblox Creator Documentation

You can check core script source to see what value/enum value it uses exactly.

Try something like 10e4 to override everything for those keybinds.

1 Like

@buildthomas Thanks, I tried:

local ContextActionService  = game:GetService("ContextActionService")
local function OpenTextBox(ActionName, InputState, InputObject)
	print(InputState, InputObject.KeyCode)
end

game:GetService("ContextActionService"):BindActionAtPriority("Test", OpenTextBox, 
    false, 3000, 
	Enum.KeyCode.I, Enum.KeyCode.O, Enum.KeyCode.K)

But for some reason, only Enum.UserInputState.End is being intercepted for keys I and O…

Seeing this in Studio with this code:

image

If you are testing this in Studio, make sure “Respect Studio shortcuts” in settings > Studio is disabled. I think O/I might also be normal Studio shortcuts in addition to being in-game shortcuts.

1 Like

Now that’s perfect.

  1. In short, to intercept keys I and O (zoom), I have to use BindActionAtPriority with a high value (3000).
  2. And for this to work perfectly within Studio, I must disable the option “Respect Studio shortcuts” in settings > Studio.

Thank you!

1 Like

This topic was automatically closed after 8 days. New replies are no longer allowed.