Lua Question about Keybinds using input.IsKeyDown()

I made a keybind to execute a function using input.IsKeyDown() and the Think hook.

My problem is that when the chat box or the main menu is open the key check is still beeing done which causes the function to be executed when I’m typing in the chatbox (f.e.).

I’ve searched for quite alot of solutions such as using vgui.GetKeyboardFocus() to check if the current focused panel is the “main game” panel, but haven’t been successful.

Anyone have any ideas ?

[lua]if LocalPlayer():IsTyping() then
return
end[/lua]

At the beginning of your func.

Thanks for the quick help. That will fix the problem with the chat box & console,
but I still have the problem for when I have a random panel focused or the main menu open and press the keybind.

bump



function GM:PlayerBindPress(ply, bind, pressed)
        if (bind == "slot1") then
           ply:ChatPrint("Hi")
      end
end


using this I would to have to forcefully create a bind on the client

Anyone know how to check if the focus is on the “main game” panel? The same way binds (like WASD movement) don’t work when you are on the Main Menu?

You can add a conCommand using a bind.

Found the solution for my problem:


if LocalPlayer():IsTyping() or gui.IsGameUIVisible() then return end

I thought that this: gui.IsGameUIVisible() was refering to the “ingame UI” but it is actually refering to the Game Menu Overlay.