move emulate_key_event() to utils