function KeyboardMovement.Enable(l)if not UserInputService.KeyboardEnabled then return end local V=0 local C=0 local x=0 local G=0 local Y=function()MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(x+G,0,V+C)MasterControl:AddToPlayerMovement(currentMoveVector)end local r=function(l,C,x)if C==Enum.UserInputState.Begin then V=-1 elseif C==Enum.UserInputState.End then V=0 end Y()end local N=function(l,V,x)if V==Enum.UserInputState.Begin then C=1 elseif V==Enum.UserInputState.End then C=0 end Y()end local i=function(l,V,C)if V==Enum.UserInputState.Begin then x=-1 elseif V==Enum.UserInputState.End then x=0 end Y()end local T=function(l,V,C)if V==Enum.UserInputState.Begin then G=1 elseif V==Enum.UserInputState.End then G=0 end Y()end local d=function(l,V,C)MasterControl:SetIsJumping(V==Enum.UserInputState.Begin)end ContextActionService:BindActionToInputTypes("\102\111\114\119\097\114\100\077\111\118\101\109\101\110\116",r,false,Enum.PlayerActions.CharacterForward)ContextActionService:BindActionToInputTypes("\098\097\099\107\119\097\114\100\077\111\118\101\109\101\110\116",N,false,Enum.PlayerActions.CharacterBackward)ContextActionService:BindActionToInputTypes("\108\101\102\116\077\111\118\101\109\101\110\116",i,false,Enum.PlayerActions.CharacterLeft)ContextActionService:BindActionToInputTypes("\114\105\103\104\116\077\111\118\101\109\101\110\116",T,false,Enum.PlayerActions.CharacterRight)ContextActionService:BindActionToInputTypes("\106\117\109\112\065\099\116\105\111\110",d,false,Enum.PlayerActions.CharacterJump)local function y()local l=getHumanoid()if l then MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(0,0,0)V,C,x,G=0,0,0,0 MasterControl:SetIsJumping(false)end end local function b(l)MasterControl:SetIsJumping(false)end SeatJumpCn=UserInputService.InputBegan:connect(function(l,V)if l.KeyCode==Enum.KeyCode.Backspace and not V then local l=getHumanoid()if l and(l.Sit or l.PlatformStand)then MasterControl:DoJump()end end end)TextFocusReleasedCn=UserInputService.TextBoxFocusReleased:connect(y)TextFocusGainedCn=UserInputService.TextBoxFocused:connect(b)WindowFocusReleasedCn=UserInputService.WindowFocused:connect(y)end function KeyboardMovement.Disable(l)ContextActionService:UnbindAction("\102\111\114\119\097\114\100\077\111\118\101\109\101\110\116")ContextActionService:UnbindAction("\098\097\099\107\119\097\114\100\077\111\118\101\109\101\110\116")ContextActionService:UnbindAction("\108\101\102\116\077\111\118\101\109\101\110\116")ContextActionService:UnbindAction("\114\105\103\104\116\077\111\118\101\109\101\110\116")ContextActionService:UnbindAction("\106\117\109\112\065\099\116\105\111\110")if SeatJumpCn then SeatJumpCn:disconnect()SeatJumpCn=nil end if TextFocusReleasedCn then TextFocusReleasedCn:disconnect()TextFocusReleasedCn=nil end if TextFocusGainedCn then TextFocusGainedCn:disconnect()TextFocusGainedCn=nil end if WindowFocusReleasedCn then WindowFocusReleasedCn:disconnect()WindowFocusReleasedCn=nil end MasterControl:AddToPlayerMovement(-currentMoveVector)currentMoveVector=Vector3.new(0,0,0)MasterControl:SetIsJumping(false)end return KeyboardMovement
--
function KeyboardMovement:Enable()
	if not UserInputService.KeyboardEnabled then
		return
	end
	
	local forwardValue  = 0
	local backwardValue = 0
	local leftValue = 0
	local rightValue = 0
	
	local updateMovement = function()
		MasterControl:AddToPlayerMovement(-currentMoveVector)
		currentMoveVector = Vector3.new(leftValue + rightValue,0,forwardValue + backwardValue)
		MasterControl:AddToPlayerMovement(currentMoveVector)
	end
	
	local moveForwardFunc = function(actionName, inputState, inputObject)
		if inputState == Enum.UserInputState.Begin then
			forwardValue = -1
		elseif inputState == Enum.UserInputState.End then
			forwardValue = 0
		end
		updateMovement()
	end
	
	local moveBackwardFunc = function(actionName, inputState, inputObject)	
		if inputState == Enum.UserInputState.Begin then
			backwardValue = 1
		elseif inputState == Enum.UserInputState.End then
			backwardValue = 0
		end
		updateMovement()
	end
	
	local moveLeftFunc = function(actionName, inputState, inputObject)	
		if inputState == Enum.UserInputState.Begin then
			leftValue = -1
		elseif inputState == Enum.UserInputState.End then
			leftValue = 0
		end
		updateMovement()
	end
	
	local moveRightFunc = function(actionName, inputState, inputObject)	
		if inputState == Enum.UserInputState.Begin then
			rightValue = 1
		elseif inputState == Enum.UserInputState.End then
			rightValue = 0
		end
		updateMovement()
	end
	
	local jumpFunc = function(actionName, inputState, inputObject)
		MasterControl:SetIsJumping(inputState == Enum.UserInputState.Begin)
	end
	
	-- TODO: remove up and down arrows, these seem unnecessary
	ContextActionService:BindActionToInputTypes("forwardMovement", moveForwardFunc, false, Enum.PlayerActions.CharacterForward)
	ContextActionService:BindActionToInputTypes("backwardMovement", moveBackwardFunc, false, Enum.PlayerActions.CharacterBackward)
	ContextActionService:BindActionToInputTypes("leftMovement", moveLeftFunc, false, Enum.PlayerActions.CharacterLeft)
	ContextActionService:BindActionToInputTypes("rightMovement", moveRightFunc, false, Enum.PlayerActions.CharacterRight)
	ContextActionService:BindActionToInputTypes("jumpAction", jumpFunc, false, Enum.PlayerActions.CharacterJump)
	-- TODO: make sure we check key state before binding to check if key is already down
	
	local function onFocusReleased()
		local humanoid = getHumanoid()
		if humanoid then
			MasterControl:AddToPlayerMovement(-currentMoveVector)
			currentMoveVector = Vector3.new(0, 0, 0)
			forwardValue, backwardValue, leftValue, rightValue = 0, 0, 0, 0
			MasterControl:SetIsJumping(false)
		end
	end
	
	local function onTextFocusGained(textboxFocused)
		MasterControl:SetIsJumping(false)
	end
	
	SeatJumpCn = UserInputService.InputBegan:connect(function(inputObject, isProcessed)
		if inputObject.KeyCode == Enum.KeyCode.Backspace and not isProcessed then
			local humanoid = getHumanoid()
			if humanoid and (humanoid.Sit or humanoid.PlatformStand) then
				MasterControl:DoJump()
			end
		end
	end)
	
	TextFocusReleasedCn = UserInputService.TextBoxFocusReleased:connect(onFocusReleased)
	TextFocusGainedCn = UserInputService.TextBoxFocused:connect(onTextFocusGained)
	-- TODO: remove pcall when API is live
	WindowFocusReleasedCn = UserInputService.WindowFocused:connect(onFocusReleased)
end

function KeyboardMovement:Disable()
	ContextActionService:UnbindAction("forwardMovement")
	ContextActionService:UnbindAction("backwardMovement")
	ContextActionService:UnbindAction("leftMovement")
	ContextActionService:UnbindAction("rightMovement")
	ContextActionService:UnbindAction("jumpAction")
	
	if SeatJumpCn then
		SeatJumpCn:disconnect()
		SeatJumpCn = nil
	end
	if TextFocusReleasedCn then
		TextFocusReleasedCn:disconnect()
		TextFocusReleasedCn = nil
	end
	if TextFocusGainedCn then
		TextFocusGainedCn:disconnect()
		TextFocusGainedCn = nil
	end
	if WindowFocusReleasedCn then
		WindowFocusReleasedCn:disconnect()
		WindowFocusReleasedCn = nil
	end
	
	MasterControl:AddToPlayerMovement(-currentMoveVector)
	currentMoveVector = Vector3.new(0,0,0)
	MasterControl:SetIsJumping(false)
end

return KeyboardMovement
