Check that your Cakewalk software recognizes your MIDI interface hardware. Launch SONAR, select "Options" from the toolbar menu, then choose "MIDI Devices" from the drop-down menu. Make sure that the box beside your desired MIDI interface is checked. This is the port to which your keyboard's MIDI In and MIDI Out cables connect. Verify that SONAR is receiving MIDI data by checking the MIDI input/output activity indicator which opens on the right of your taskbar when SONAR starts.
If you are using sounds generated by the keyboard itself, the audio outputs of the keyboard must be connected to the audio inputs that SONAR uses to record. MIDI data does not carry audio signals, only instructions that a keyboard or other sound device interprets into music. Alternatively, the keyboard audio may be connected to an amp or PA for monitoring while recording.
When using your keyboard to record MIDI data, check that the MIDI track properties are correct. Select the track you wish to use, right-click anywhere on the track header at the left -- except for the track icon -- and select "Track Properties" from the dialog box that opens. Set the input and output to the MIDI interface to which your keyboard connects. Set "Channel" to the MIDI channel that your keyboard uses to transmit. Check the channel setting on the keyboard itself, and ensure that it's transmitting on the correct channel.
Your MIDI keyboard can also control virtual instruments in the Cakewalk program. To do this, you must connect the keyboard to the virtual instrument. Verify the MIDI track setup, and route the output of the track to the virtual instrument you wish to use. Virtual instruments may be prone to latency, which is the interval between a key press on the MIDI keyboard and the time the note sounds through the virtual instrument. Avoid latency by selecting a virtual instrument for your track only after recording the track.