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

Turn off Key-Activated Buttons while typing?

Asked by 6 years ago
Edited 6 years ago

So i have some buttons in my game which can be activated by being clicked or by activating a hotkey. Problem is, the hotkey still opens the UI while the player is typing.

Is there a specific way to know when the player is typing so the hotkey doesn't activate while chatting?

[EDIT #1] I tried using ContextActionService, but the only events I can see for use are LocalToolEquipped and LocalToolUnequipped. How would I bind hotkeys to my UI buttons using ContextActionService?

0
What are you currently using for your buttons? UserInputService? saenae 318 — 6y
0
Yes, UserInputService. ReadyHappiness 109 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago

Using UserInputService is fine, there is a second parameter, a boolean, which is set to true if a player's input is being processed by the game, like inputting text into a text box, and most commonly, chatting.

UIS.InputBegan:Connect(function(input, gpe)  -- remember to define UserInputService
    if gpe then return end -- if they are chatting, stop the function

    -- your code here
end)

With ContextActionService, you bind actions with a method, not an event. That method is called BindAction. You can also create mobile buttons (they show only for mobile users!) with this method, and bind multiple keys, which is useful so you don't have to create multiple if statements just to check if the key is one of the keys that can run the code.

local function onKeyPress()
    -- code
end

CAS:BindAction(
    "Name", -- action name. put whatever
    onKeyPress, -- remember, don't add brackets, this is the function to bind
    false, -- want a mobile button? Set to true for one.
    Enum.KeyCode.E, -- just an example. you can bind multiple keys, the fourth arg is a tuple
    Enum.KeyCode.ButtonY -- example. keep using , and bind other keys if wanted
)
0
THANK YOU! The key-activated button no longer activates while chatting. ReadyHappiness 109 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

It might have something to do with what method you are using to bind the buttons to the hotkeys. I have a similar system in my game except this problem doesn't seem to occur, are you using the Context Action Service to bind the keys? If not, I strongly suggest migrating to it.

0
I wrote a response on Edit #1. ReadyHappiness 109 — 6y

Answer this question