I don’t understand your question. There is nothing here that processes a ‘PRESS’ whatever that is. You need to add more context. In particular, any code that would cause a Trigger2D to fire.
If you want to do that with efficiency, start considering the animator component as a feedback to the player. it is better to keep the game logic away from feedback such as animations, sounds, user interfaces…
If you want to know if an object is in attack mode, set this mode elsewhere such as a state in a FSM. This state may change the animator on its enter event.