Refactor and fix do_sendkey (Jan Kiszka).