Ok
let’s isolate it then.
Plug your MIDI out into your MIDI in and record it back into a new track, is it aligned?
If yes, then the problem is most likely with the keyboard.
Try the same loop-back test with audio. Is the off-set the same in Audio as MIDI?
If yes, adjust the record offset.
If no, then it’ll be a MIDI timing issue and I’m not much chop there.
Cheers,
PC