As an offensive player, you can only stay in the key for 3 seconds.
A referee won’t necessarily penalise you unless you are an active player. For example, you could sit in the key for more than 3 seconds if you have no influence in the game with no penalty.
But if you then have an active influence in the game, that would be a penalty.
Defensive players have no time restriction in this area.