1) The 3 second count is suspended as soon as a shot is taken, and is reset as soon as a rebound is controlled. It doesn't reset when the ball hits the rim. There is no count while a shot ball is bouncing around before someone controls it.
2) When an offensive player is in the key and the ball is passed to him, the count is suspended for that player. The count is suspended as long as that player is in the process of making an attempt to score. It is at the discretion of the referee to determine a) whether or not the offensive player is making a valid attempt to score and b) how long to wait for the offensive player to make a valid attempt prior to resuming the 3 second count. So, once the ball is entered into the post, it is at the complete discretion of the referee whether or not a 3 second violation has occurred. You can count as high as you want... as long as the ref is satisfied that the player is making (or is about to make) a valid scoring move, it is not a violation.