javascriptdom-eventsaddeventlistenermousemovemousedown

Mousemove event added in mousedown event keeps firing while the mouse is not moving


I am working at a simple sequence of mouse event listeners in the form of "mousedown" -> "mousemove" -> "mouseup". What I am trying to do is add two event listeners for mousemove and mouseup when the mousedown event fires.

My code looks like this:

document.addEventListener("mousedown",stagesContainerGrabMouseDownHandler)

function stagesContainerGrabMouseDownHandler(ev){
      document.addEventListener("mousemove",stagesContainerGrabMouseMoveHandler);
        document.addEventListener("mouseup",stagesContainerGrabMouseUpHandler)
}

function stagesContainerGrabMouseMoveHandler(ev){
        console.log(12)
}

function stagesContainerGrabMouseUpHandler(ev){
    document.removeEventListener("mousemove",stagesContainerGrabMouseMoveHandler);
    document.removeEventListener("mouseup",stagesContainerGrabMouseUpHandler);
}

The problem is that when I keep the mouse pressed, the mousemove event keeps firing even if my mouse stays still. I am using Chrome.


Solution

  • So I have found the culprit. I didn't even think to look there. I am running a script in the background with AutoHotKey and for some reason it seems that it interacts with my page. Turning it off solved the issue.