You can save the mouse position to some variables at the end of every frame. Then you could compare the previous frame’s mouse position with the current one. If they’re different, the mouse moved. You can get the velocity of the mouse by subtracting the previous position from the current, getting the magnitude of that and dividing but the length of a frame.
Having it work when the cursor is already in the corner of the screen isn’t possible with the mouse api exposed by browsers.