If the other keyboard does work, the iMac keyboard may have gotten damaged in some way. Any fluid spills or accumulation of crumbs between the keys? There's not much I can think of that would solve this, apart from shaking all the crumbs out, letting it dry out (if fluid may be involved) and trying again after a reboot of your Mac. If the problem persists you may need to invest in a new keyboard.