Are you trying to record, or just play ...using your computer's sound card?
Usually the time delay is from using a 'soft synth' set of sounds. The delay is because the computer has to generate the tones using the CPU power. Most cards have a 'built in' sound set, that is not using the CPU. Those tones may not be as 'nice'...but will track with your playing, right on time. I'm not familiar with your soundcard...but with my SoundBlaster Live....there isn't any delay, even using the Soundfonts or the 'on card' synth.
also, make sure you aren't creating a 'data loop'...that is sort of like feedback. Looping the midi in ,to the midi thru, to the midi out. The simplist way to eliminate this is to unplug the Casio 'midi in' plug