Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to temporarily disable a specific key on the keyboard?

For my game, I need to temporarily disable a specific key, which is the Z key on the keyboard. What I managed to do is disable the player's control which are the keys WASD & space with this local script.

local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()
Controls:Disable()
Controls:Enable()

But I also want to temporarily disable the Z key. Someone can help me with the Z key please

1 answer

You can disable certain keys through ContextActionService:

local ContextActionService = game:GetService("ContextActionService")

ContextActionService:BindActionAtPriority("DisableZ", function()
	return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.Z)

You can then enable it back by setting it true:

local ContextActionService = game:GetService("ContextActionService")

ContextActionService:BindActionAtPriority("EnableZ", function()
	return Enum.ContextActionResult.Pass
end, true, Enum.ContextActionPriority.High.Value, Enum.KeyCode.Z)

3 comments

0

It work to disable the key but it don't work to enable it back do u know why?

0

I don't think I typed it right, lemme research

0

try this, it might not work tho

This discussion is preserved as it was. New answers, comments, and votes are closed.