Currently we emit press events of combined keys first, then emit release events by reverse order. But it doesn't match with physical keyboard if the keys contain continued & repeated keys.
For example, (qemu) sendkey a-b-b Current emited events: (actually the second 'presse b' and 'release b' can't be identified by guest, the interval is too short) press a press b press b release b release b release a Correct events order of physical keyboard: press a press b release b press b release b release a This patch fixed the event order if keys contain continued & repeated keys. his patch based on: http://lists.nongnu.org/archive/html/qemu-devel/2014-09/msg05150.html Cc: Gerd Hoffmann <kra...@redhat.com> Signed-off-by: Amos Kong <ak...@redhat.com> --- V2: rebase this patch on Gerd's better fix of release order --- ui/input-legacy.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ui/input-legacy.c b/ui/input-legacy.c index a698a34..3fd3e83 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -95,9 +95,17 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time, for (p = keys; p != NULL; p = p->next) { qemu_input_event_send_key(NULL, copy_key_value(p->value), true); qemu_input_event_send_key_delay(hold_time); - up = g_realloc(up, sizeof(*up) * (count+1)); - up[count] = copy_key_value(p->value); - count++; + + /* release event will be emitted immediately if next key is repeated */ + if (p->next && p->value->kind == p->next->value->kind && + p->value->qcode == p->next->value->qcode) { + qemu_input_event_send_key(NULL, copy_key_value(p->value), false); + qemu_input_event_send_key_delay(hold_time); + } else { + up = g_realloc(up, sizeof(*up) * (count+1)); + up[count] = copy_key_value(p->value); + count++; + } } while (count) { count--; -- 1.9.3