A man who was being arrested by police attacked one of the officers using a key to inflict a facial injury, a court heard.