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.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
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.
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
There seems to be one at AdaFruit, called USB Charger Doctor. It looks simple, but efficient.