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

How can I make sure User Keyboard Input halts when a text box is in focus?

Asked by 7 years ago

I tried using the line if script.Parent.Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar.FocusLost then but that didn't even work. What I'm trying to do is make it so that when keys are pressed and the chat or another gui is in focus, it won't run the function.

Here is the full script, for anyone who is interested.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hmnid = char:WaitForChild("Humanoid")

function onKeyPress(inputObject, gameProcessedEvent)
    if script.Parent.Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar.FocusLost then
        if inputObject.KeyCode == Enum.KeyCode.K then
            if hmnid.CameraOffset.x ~= 5 then
                hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X + 0.5, hmnid.CameraOffset.Y, hmnid.CameraOffset.Z)
                print("CameraOffset X value increased.")
            else
                print("CameraOffset not changed.")
            end
        end
        if inputObject.KeyCode == Enum.KeyCode.H then
            if hmnid.CameraOffset.x ~= -5 then
                hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X - 0.5, hmnid.CameraOffset.Y, hmnid.CameraOffset.Z)
                print("CameraOffset X value decreased.")
            else
                print("CameraOffset not changed.")
            end
        end
        if inputObject.KeyCode == Enum.KeyCode.J then
            if hmnid.CameraOffset.z ~= 5 then
                hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X, hmnid.CameraOffset.Y, hmnid.CameraOffset.Z + 0.5)
                print("CameraOffset Z value increased.")
            else
                print("CameraOffset not changed.")
            end
        end
        if inputObject.KeyCode == Enum.KeyCode.U then
            if hmnid.CameraOffset.z ~= -5 then
                hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X, hmnid.CameraOffset.Y, hmnid.CameraOffset.Z - 0.5)
                print("CameraOffset Z value decreased.")
            else
                print("CameraOffset not changed.")
            end
        end
        if inputObject.KeyCode == Enum.KeyCode.Y then
            if hmnid.CameraOffset.y ~= 5 then
                hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X, hmnid.CameraOffset.Y + 0.5, hmnid.CameraOffset.Z)
                print("CameraOffset Y value increased.")
            else
                print("CameraOffset not changed.")
            end
        end
        if inputObject.KeyCode == Enum.KeyCode.N then
            if hmnid.CameraOffset.y ~= -5 then
                hmnid.CameraOffset = Vector3.new(hmnid.CameraOffset.X, hmnid.CameraOffset.Y - 0.5, hmnid.CameraOffset.Z)
                print("CameraOffset Y value decreased.")
            else
                print("CameraOffset not changed.")
            end
        end
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
0
use the second arg, gameProcessedEvent. User#5423 17 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

You could check if game:GetService("UserInputService"):GetFocusedTextBox() is nil, because that means there is no textbox is focused, so it won't run if you are focused on a text box

0
basically a if statement lik. if not game:GetService("UserInputService"):GetFocusedTextBox() then ScriptedFuel 103 — 7y
Ad

Answer this question