User Input Service Problem

Hi DevForum users!

So i was trying to do a key combination, but, for some reasson, LeftControl isnt detected by IsKeyDown() method.

I tried using different methods to obtain the keys, such as Enum.KeyCode, Enum.KeyCode:FromValue, and Enum.KeyCode:FromName.

Code:

UserInputService.InputBegan:Connect(function(input,gameProcessed)
	if input.KeyCode == Enum.KeyCode.Z then
		if UserInputService:IsKeyDown(Enum.KeyCode:FromName("LeftControl")) or UserInputService:IsKeyDown(Enum.KeyCode:FromName("RightControl")) then
			--Any code i place here will not work.
		end
	end
end)
2 Likes

have you tried this in game rather than in studio? pretty sure this doesnt work because studio has undo binded to ctrl + z

it worked for fine for me in the server and clients mode

1 Like

Try that the other way around.. You’ll have to press Z first however.

--LocalScript in StarterPlayerScripts
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.LeftControl or
		input.KeyCode == Enum.KeyCode.RightControl then
		if UserInputService:IsKeyDown(Enum.KeyCode.Z) then
			print("Z + Ctrl detected")
		end
	end
end)
1 Like

Maybe try a different keybind to test in studio. And try testing ctrl+z in the roblox player to see if studio is the issue. I tested the code and printed all keys being pressed and z never shows up after you press ctrl. ctrl x would work.

1 Like

Ctrl + Z, Ctrl + X are bound to certain operations in studio, hence it won’t work in studio. In game it would work perfectly fine

2 Likes

hello! there is a very useful method on InputObjects, called IsModifierKeydown(), it takes 1 enum, an Enum.ModifierKey, and CTRL is one of the keys in that enum.

you’d simply do:

if input:IsModifierKeyDown(Enum.ModifierKey.Ctrl)

i’m not sure if it detects both of the Ctrl keys or not.

1 Like

spoodr is 100% right. This is totally the case.

1 Like

they probably are :), i just wanted to share a little shortcut i’ve discovered a while back.

EDIT: on another note, there is a setting in Studio called “Respect studio shortcuts when game has focus”, you’d tick that off, and it will not sink any keys bound to studio shortcuts whilst you are testing

3 Likes

And thank you .. I was a but upset the studio did that in the first place. Seems I missed a few points here.

1 Like

Thanks everyone, ill test every solution to see which one works for me.

1 Like

Thing is, the engine doesn’t fire when regular key is pressed after pressing CTRL and holding it, so IsModifierKeyDown is useless here, it’s likely an engine bug

Even the solution here ^ does no longer work, im positive it’s an engine bug, consider creating bug report

or it could be the case @Razor_IB said, which is still weird cause z + ctrl works, but not ctrl + z