Although this was already answered in the comments of your question, I want to add an answer as to how I resolved this issue to record piano sounds with a distortion pedal in a similar manner.
As Your Uncle Bob pointed out, the MIDI keyboard itself does not make sound. So, what I did is I plugged the MIDI keyboard into my computer, then got a 3.5mm to 1/4" converter to take the headphone output of my computer and plug it into the input of the pedal, then plugged the output of the pedal into my audio interface, and designated the audio interface channel as the audio input for the track in my DAW.
In order to do this in the same DAW you will need a way to arm both your instrument track and your audio track, but I did it by using two DAWs, one just for the MIDI -> instrument conversion, and one solely to record audio in.
It was an awkward setup, but it worked. It just means you can't have any other audio sources playing through your computer (especially monitoring the input in your DAW) or it will send those through the pedal also.
Hopefully that is helpful!