How can I detect the mouse is moving through code?

I just want to be able to play certain animations if the mouse is moving in a certain direction. somethng like this

if(mouse is moving to the left){ animation.Play("WhateverIWant"); }

I’m not sure what I need to enter for unity to detect my mouse is moving in a certain direction.

The easiest way would probably be to store the mouse location and then compare it to the current mouse coordinate to see if it is moving to the left.
For example:

Vector3 lastMouseCoordinate = Vector3.zero;
void Update()
{
    // First we find out how much it has moved, by comparing it with the stored coordinate.
    Vector3 mouseDelta = Input.mousePosition - lastMouseCoordinate;

    // Then we check if it has moved to the left.
    if(mouseDelta.x < 0) // Assuming a negative value is to the left.
        animation.Play("WhateverIWant");

    // Then we store our mousePosition so that we can check it again next frame.
    lastMouseCoordinate = Input.mousePosition;
}

Depending on how you want it to work, but that would be a simple example.

Makes sense?

You will need to sample the mouse position periodically and compare that position to the previous position. Sampling every frame is likely too frequently. If the difference in the magnitude of the x move is above some threshold, then you would call it a directional move. You can get the current mouse position using Input.mousePositon. You can create a sampling rate by either creating your own timer or by using InvokeRepeating().

Note if you are targeting multiple platforms with your code, you may want to convert your mouse coordinates into viewport coordinates.

C# code // THIS IS A CODE TO DETECT MOUSE MOVING AND AFTER SOME TIMER TIME THE CURSOR DESAPPEAR // C# code

float timeLeft;
	float visibleCursorTimer = 10.0f;
	float cursorPosition;
	bool catchCursor = true;

	void Update(){

		if(catchCursor){
			catchCursor = false;
			cursorPosition = Input.GetAxis("Mouse X");
		}

		if(Input.GetAxis("Mouse X") == cursorPosition)
		     {
			     print("Mouse stop");
			     timeLeft -= Time.deltaTime;
			     if ( timeLeft < 0 )
				     {		        
					 timeLeft = visibleCursorTimer;
					  Cursor.visible = false;
					  catchCursor=true;
				     }

			 }else{
			 	timeLeft = visibleCursorTimer;
				Cursor.visible = true;
			 }			

	}