Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to temporarily disable a specific key on the keyboard?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
It work to disable the key but it don't work to enable it back do u know why? SaitamaSaan 9 — 5y
0
I don't think I typed it right, lemme research Trollapse 89 — 5y
0
try this, it might not work tho Trollapse 89 — 5y
Ad

Answer this question