Check the connection from the keyboard to the tower. Make sure it is firmly inserted. If it is a USB keyboard then try a different USB port. if it still fails, then try your keyboard on a separate compute. If it is a PS/2 keyboard and the keyboard works fine on a different machine, then your PS/2 port is junk and you should purchase a USB keyboard. - process of elimination.
pauls totally right lol seriously