For a keyboard, you're right; you can just plug it straight into your computer.
As for an electric guitar, the answer is a bit more complicated. To get the absolute most authentic sound, you need to hook it up to an amp and use a mic to record the amp. However, there are many other ways to do it which will get tones that are almost as good, and are a lot cheaper.
You can plug your guitar directly into your soundcard, but it probably won't be at the correct volume; you may need a mixer or preamp to boost the signal to a usable level.
This will also give you pretty crappy tone. The way to remedy that is with amp modelers. You can use an external modeler, such as a POD (and depending on your budget, there are cheaper and more expensive versions). You can also use plugins such as Guitar Suite. Guitar suite is free, and it's what I use. I highly reccomend it.
Amp modelers will never be able to get you quite the same sweet tone that you can get from miking a genuine tube amp, but some can come close enough that most people won't be able to tell the difference.