Cant move other way after i press one move button? 2d

Also, it just stops my movement out of nowhere, and I have to jump to be able to move before it happening again.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour {

public float moveSpeed;
public float jumpHeight;

// Use this for initialization
void Start () {
	
}

// Update is called once per frame
void Update () {
	
    if(Input.GetKeyDown(KeyCode.Space))
    {
        GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
    }

    if (Input.GetKey(KeyCode.D))
    {
        GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, 0);
    }

    if (Input.GetKey(KeyCode.A))
    {
        GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, 0);
    }
}

}

first of all don’t use

     GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, 0);

because it reduces your performance.
and don’t use input .getkey
you can use input.getaxisraw so you don’t have to use alot of codes.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

                       public class a : MonoBehaviour {

               public float moveSpeed=5;
        public float jumpHeight=5;
           public Rigidbody2D rig;

void Start(){

	rig = GetComponent<Rigidbody2D> ();
}

void Update(){

         //when you use Input.GetAxisRaw if you press A or left arrow it means you go left and D and right arrow means you should go right

	if (Input.GetAxisRaw ("Horizontal") != 0) {
		rig.velocity = new Vector2 (moveSpeed*Input.GetAxisRaw("Horizontal"),rig.velocity.y);
                    transform.localScale = new Vector3 (1*Input.GetAxisRaw("Horizontal"),1,1);
	}
	if (Input.GetAxisRaw ("Horizontal") == 0) {
		rig.velocity = new Vector2 (0,rig.velocity.y);
	}

	if (Input.GetButtonDown ("Jump") && rig.velocity.y==0 ) {
		rig.velocity = new Vector2 (rig.velocity.x,jumpHeight);
	}

}

}