Handle button press event only when appropriate.