fixed key trap function