How can I move the mouse position whilst key is pressed?

I’m using Unity 5.5.2 and even if I create a new Unity project, in the editor, if I hold down a key (any key), then my mouse position locks and I cannot move it.

I want my player to move towards my mouse position (no click) and I also want to be able to hold down a key (e.g. space bar) to continuously fire. When my key is held down, the mouse does not move. Try it, just create a new Unity project, hit run and hold down a key, mouse is locked!

How can I change that?

If your space is in 2D (in 3D need some changes for this code) this should work:

private Vector3 moveDirection;

in Update function:

Vector3 currentPosition = transform.position;

if( Input.GetButton("Fire1") ) {
  Vector3 moveToward = Camera.main.ScreenToWorldPoint( Input.mousePosition );
  moveDirection = moveToward - currentPosition;
  moveDirection.z = 0; 

 Vector3 target = moveDirection * moveSpeed + currentPosition;
    transform.position = Vector3.Lerp( currentPosition, target, Time.deltaTime );

P.S. If you want to run after mouse position without pushing it, just remove “if” statement