Detect mouse movement

Hello!

I am trying to make a very simple maze game. I am controlling the movement using the mouse.

By biggest problem is that when I hit a wall, my object stops moving, but the mouse arrow still moves, and it is very likely that eventually the mouse cursor will reach the limits of the screen, making it impossible to move the object to the left (assuming the cursor has hit the left side of the screen).

I am now using the following scripting:

function Start()
{
    Mouse.hide();
    stage.addEventListener(MouseEvent.MOUSE_MOVE, StartMoving);
}
Start();
 
function StartMoving(e:MouseEvent)
{
    prevX = curX;
    curX = stage.mouseX;
    
    prevY = curY;
    curY = stage.mouseY;
    

    deltaX = curX - prevX;
    deltaY = curY - prevY;
    trace("prevx: "+prevX+" prevy: "+prevY+" currx:"+curX+" cury: "+curY+" deltax: "+deltaX+" deltaY: "+deltaY);
    
    oldX = mySquare.x;
    oldY = mySquare.y;
    
    mySquare.x = mySquare.x + deltaX/ratio;
    mySquare.y = mySquare.y + deltaY/ratio;

    //mySquare.x = curX;
    //mySquare.y = curY;
    
    if (mySquare.hitTestObject(wall1) || mySquare.hitTestObject(wall2))
    {
        mySquare.x = oldX;
        mySquare.y = oldY;
    }
    
    if (mySquare.hitTestObject(targetObj))
    {
        targetObj.gotoAndStop(2);
    } else targetObj.gotoAndStop(1);
 
    e.updateAfterEvent();
}

You can see that i am detecting mouse cursor postition.

Is there any way I can detect mouse movement (not position), but movement from the device itself, so that my object can be moved to the left even if the pointer is at the left side of the screen?

Or maybe is there a way to set the position of the mouse via scripting?

Thank you!