Enum.KeyCode not working for 3 keys

I’ve been trying to use a key, which was the X key and it didn’t work. I thought it was a script error but I used this and nothing was printing, and every other key were printing. This was the same for C and V.

uis.InputBegan:Connect(function(input)
	print(input.KeyCode)
end)

What is the issue? Is it a problem on my end, or is it a bug? I also noticed that the keys only print when I’m typing in the chat in-game.

3 Likes

Try doing this instead:

uis.InputBegan:Connect(function(input, x)
  if x then return end
  if input.KeyCode == Enum.KeyCode.X then
    -- do your stuff here
  end
end)

If you really don’t want to use enum, use: input.KeyCode.Name == "X" instead.

1 Like

I tried the first and second methods. None of them worked either.

Try using this UserInputService | Roblox Creator Documentation
It is advised to read the entire API-reference.

Then there’s something wrong on your end.

Could it got to do with the fact that c, v and x all have things that they do when you hold down ctrl and the key.

1 Like

I didn’t even think about that. I’ve heard of similar glitches where sometimes the keyboard by default uses those shortcuts without even holding down control.

2 Likes

It’s probably the keyboard I’m using because, I was just holding down the control key and the keys registered then, for some reason.

Are you using a localscript, and if so, where is it? And what is the “uis” variable?

its local, and the uis variable is

local uis = game:GetService("UserInputService")

Well try this

local uis = game:GetService("UserInputService")
local index = {Enum.KeyCode.X,Enum.KeyCode.C,Enum.KeyCode.V}

uis.InputBegan:Connect(function(input,processed)
  if table.find(index,input.KeyCode) and not processed then
   print("Pressed Key: "..tostring(input.KeyCode))
  end
end)

It will only print when you pressed the keys when you aren’t typing or chatting

What script type were you used?
If it wasn’t a LocalScript then this is the problem, Try putting the code in StarterPlayer > StarterPlayerScripts.

it was a local script inside of starterpack

these lines don’t work either.

may i ask why did you put it in starterpack

the problem is in your end, you might be doing something that is breaking it

because it works with every other key, besides I’ve already put it in starterGui, and into the starterPlayer, and it still didn’t work. I don’t know it is probably something wrong with my keyboard or something.

Try putting it in StarterPlayer.StarterPlayerScripts.

I’ve already put the script into where ever it could go. nothings changed

Can you please share your script?