Move Hook key detection only works sometimes

I am working with some code that switches a client console command when J is pressed
Pressing J only actually works and toggles the command once every 4-10 times. The other times nothing happens and the print statements show the code only gets to step 3 (see green print statements below)

hook.Add("Move", "DetectBindings", function(ply, mv)
	--print("1. KEY PRESSED")
	if gui.IsGameUIVisible() then return end 
	if vgui.CursorVisible() then return end 
	if ply:IsTyping() then return end 
	--print("2. PASSED 1st CHECKS")
	if CurTime() < delay then return end
	--print("3. PASSED DELAY CHECKS")
	for k, v in next, cvars_to_commands do
		local get = GetConVar(k):GetInt()
		if input.WasKeyPressed(get) then
            delay = CurTime() + 0.5
            if k == "cl_thirdperson_button" then
				--print("4. IS THIRDPERSON KEY")
               local third_convar = GetConVar(v) 
               local is_third = third_convar:GetInt() == 1 and 0 or 1
				--print("5. GOING3P")
end )

As you can see, I use the print statements to see how far it got (currently commented out)
When it works, rarely, we go all the way to step 5. But when it doesn’t work, we only reach step 3.

Note: I am on a listen server. So GM:Move() should be working, but it is not.

The big question is why are you using the “Move” hook to check for keyboard input? Use “KeyPress” or “KeyRelease”…?

1 Like

Try using CreateMove hook.