Inspect the USB ports for a problem. If you're using the same Mac, try connecting the keyboard to a different USB port. You should unplug the keyboard and connect it back into your Mac with even more force. Verify that the USB port is clear of any obstructions (debris, dirt, etc.). If so, you should endeavor to get rid of it.