Here are some thoughts; I don't know if they will work, but they're what I would try. Since you mention Terminal, I expect you're beyond them, but:
If you're running a 3rd party keyboard (such as an ergonomic one), you might have a software disk that came with it in the box that could be useful.
Probably you have tried these things already? There is at least one keyboard that requires a special update:
http://support.apple.com/kb/TS1381
Failing all that, or what someone in another forum might add to this, I would expect the keyboard to be controlled by the OS. Back up critical files and jot down your internet or networking settings in case there is a problem, then reinstall system software. (Potentially a pain. But we used to have to do it almost as routine maintenance with OS 8 and 9 because things would get "confused" over time.)