The heartbeat occurs through an electric signal that travels over the tissue, causing it to contract. This signal, a so-called action potential, normally travels in a wave, leaving the tissue behind it insensitive (refractory) for further impulses for a brief while. This is shown in the simulation below, where the blue wave is the action potential, and the red wave is the refractory tissue.
See what happens, however, if you disturb the action potential with your mouse or by pressing the buttons!