How to create possession variable

I was thinking of starting to make a basic soccer game, and I realized that I needed a way to minimize the number of controls. So I was planning to make the defense keys same as the attacking on-the-ball keys. But I wasn’t sure how to get the game to know which type it is on. I thought that I would use a bool, but I wasn’t sure what event would trigger the change. If someone could either explain what to do or provide commented code, that would be great.

pseudo code

if(Input key is pressed)
{
   if(mode == attack)
   {
       ....attack code.....
   }
   else if(mode == defense)
   {
      ..defense code and stuff.....
   }
}

It’s up to you to decide when the mode is attack or defense