how long

how long do you have to wait to take a pregnancy test? does it take time or would you know right away even if it was a week ago that everything happened?