Invert movement based on mouse location

I have a strafe that is based off the mouse location, A going to the player left and D going to the players right. The problem i’m having is when the player is looking down A moves the player to the right and D to the left which can get confusing. I know how to invert the controls, but I was wondering if there is a way to invert them based on the mouse location. The two pictures are my movement controls and my character look at.