Your keyboard has a built in midi sequencer. It's probably counting in clock pulses, 96 or 192 clocks per beat. (some systems use a 100 based count, so an 1/8th note would be 50 clocks, etc) (this is not the same as your tempo setting)
Sustain is midi controller number 64, a simple on / off...