Jittery movement specifically with keys A and D

I wanted to ask this here first to see if there’s an issue with my code or if I have to make a bug report. I’m using a generic movement script plus sprint:

function on_input(self, action_id, action)
	if action_id == hash("key_w") and self.canmove.up then
		self.dir.y = 1
	elseif action_id == hash("key_s") and self.canmove.down then
		self.dir.y = -1
	elseif  action_id == hash("key_a") and self.canmove.left then
		self.dir.x = -1
	elseif action_id == hash("key_d") and self.canmove.right then
		self.dir.x = 1
	elseif action_id == hash("key_lshift") or action_id == hash("key_rshift") then
		if action.released then self.sprinting = false
		else self.sprinting = true end
...
--inside the update() function
	if self.dir == vmath.vector3(0) then --settings if moving
		self.moving = false
	else
		self.moving = true
	end


	if math.floor(vmath.length_sqr(self.dir)) == 0 then
		self.moving = false 
	else
		local n = math.floor(1/globals.framerate * self.speed)
		self.dir = self.dir * n + self.normal
	end

	if self.sprinting then
		if self.moving then
			if self.speed < self.maxspeed then
				go.animate("#", "speed", go.PLAYBACK_ONCE_FORWARD, self.maxspeed, go.EASING_OUTQUAD, 1)
			end
		end
	else
		if self.speed > self.walkspeed then
			go.animate("#", "speed", go.PLAYBACK_ONCE_FORWARD, self.walkspeed, go.EASING_OUTQUAD, 0.5)
		else
			self.speed = self.walkspeed
		end
	end
	if not self.moving then self.speed = 150 end

	local tpos = p + self.dir
	tpos.x = math.floor(tpos.x); tpos.y = math.floor(tpos.y)
	go.set_position(tpos)
...
    self.dir =  vmath.vector3(0)

Beforehand the controls were arrow keys and I had no issue. However, when I changed to WASD, pressing A and D at the same time seemed to cause slow input. I checked the self.dir variable in the update function, and the x value was swapping between -1 and 1, causing the jittery movement towards one direction. I tested this on a different windows device and the exact same thing happened.
This only ever happened with A and D. I switched around keys and it was fine. I just want to see what others have to say first before I put in a pull request.