You just need to create a variable for it.
document.onmousemove = mouseMove; document.onmousedown = mouseDown; document.onmouseup = mouseUp; var mouseState = "up"; function mouseMove(ev) { //How can I know the state of mouse from here if(mouseState=='down') { console.log('mouse down state') } if (mouseState=='up') { console.log('mouse up state') } } function mouseDown(ev) { mouseState = "down"; console.log('Down State you can now start dragging'); //do not write any code here in this function } function mouseUp(ev) { mouseState = "up"; console.log('up state you cannot drag now because you are not holding your mouse') //do not write any code here in this function }
You should watch the event on "mousemove" by running it in the console. There may be a property that indicates that the mouse state, like the keypress event, has a property that tells you whether the shift button is pressed. But this may not be compatible with the browser.
source share