For example, how could I measure the normal power consumption of my USB keyboard?
After I get my statistics, I may easily notice when a hardware keylogger gets installed, by the changed power consumption.
Alternatively, if you're up for a bit of DIY, see this project on Instructables. You'll need a multimeter, though, because that's just a passive passthrough connector that simply provides a couple of test points.
You didn't specify, but I know Windows (and probably other modern OS's) will tell you how much power is "required" for each attached USB device in the properties of each "USB Root Hub" in the Device Manager.
Regardless of that, unless you're talking about a physical hardware keylogger that has to be in-line with the keyboard, then you're not going to be able to detect it by electrical draw in the way you are suggesting (by watching the keyboard).
I would recommend this USB power meter...
I use it and it works great. Better than hacking up cables and trying to tie in a multimeter.
There seems to be one at AdaFruit, called USB Charger Doctor. It looks simple, but efficient.
Just to add Mac info to the overall solution…
You can see data for each hub & device from
menu > About this Mac > System Report > USB...
I haven't tried it but you could get a regular Mains Power Meter plug and unplug the keyboard and measure the difference.
What I have tried, is you could also connect a multimeter in series and measure the current. Like break the usb cable and connect your multimeter in between. If somebody can describe that process fully then that'd be great and a better answer than mine.
Given the Voltage(5V) and current/amps, you can measure the Power/watts.
Power(P) = Current(I) * Voltage(V)
added- now tried indrek's solution.. PC USB 2.0 Cable Device Voltage Current Meter Tester