Enum.KeyCode.F not firing for InputEnded

Using a plugin I have a script where I’m trying to listen to whenever Ctrl+F is pressed but for some odd reason, the F KeyCode is not firing Enum.KeyCode.Begin when the button is pressed. Forgive me for my messy coding.

--//GetService
local ContextActionService = game:GetService("ContentActionService")

--//Data
ButtonDown = {
["LeftControl"] = false,
["RightControl"] = false,
["F"] = false }

--//Control buttons pressed
for ButtonName, Allowed in pairs(ButtonDown) do
	if typeof(Allowed) == "boolean" then
		local ButtonFunction = function(actionName, userInputState, inputObject)
			if userInputState == Enum.UserInputState.Begin then 
				ButtonDown[ButtonName] = true
				print(ButtonDown[ButtonName])
				if ButtonDown["F"] == true and ButtonDown["RightControl"] == true then
					print("test2")
				elseif ButtonDown["F"] == true and ButtonDown["LeftControl"] == true then
					print("test2")
				end
			elseif userInputState == Enum.UserInputState.End then
				ButtonDown[ButtonName] = false
				print(ButtonDown[ButtonName])
			end
		end
		ContextActionService:BindAction(ButtonName.."Press", ButtonFunction, false, Enum.KeyCode[ButtonName])
	end
end

I have no clue what is wrong with the script, there are no errors besides the F keycode not firing on inputbegin.

I think ContextActionService is mispelled at the top, but baring that–

Correct me if Im wrong but I think studio shortcuts will sink keyboard input states. What you can do to get around this is by using UserInputService events and making sure you dont filter out gameprocessed (aka sunken) inputs.

I’m testing this now to check if it works, sorry for not responding straight away, I wasn’t at the computer for a bit.

I made something that should be easy to convert back and forth between CAS and UIS if its the studio hotkeys swallowing input:

local UserInputService = game:GetService("UserInputService")

local VALID_KEYS = {Enum.KeyCode.F}
local MODIFIER_KEYS = {Enum.KeyCode.LeftShift}

local function findValue(list, passedValue)
	for index, value in pairs(list) do
		if value == passedValue then
			return index
		end
	end
end

local isModifierDown = false
local function handleInput(inputObject)
	if findValue(MODIFIER_KEYS, inputObject.KeyCode) then
		isModifierDown = inputObject.UserInputState == Enum.UserInputState.Begin
	elseif findValue(VALID_KEYS, inputObject.KeyCode) then
		if isModifierDown then
			if inputObject.UserInputState == Enum.UserInputState.Begin then
				print("Shift + F!")
			end
		end
	end
end

UserInputService.InputBegan:Connect(handleInput)
UserInputService.InputEnded:Connect(handleInput)

I’d use this as a guideline. I didnt test it but it should help
Let me know if you need me to go into detail. Id feel bad for code dumping

1 Like

Thanks, it worked! At first it was my mind was confused as to why ContextActionService, in studio mode, was overriding the buttons, but now I get it :+1:

Yea there’s a few shortcut keys that use ‘F’ by default so Im assuming thats the case. Studio plugins + CAS play a bit weird together, but its otherwise a really good service to use in game where studio shortcuts dont swallow everything

1 Like