From patchwork Wed Mar 9 08:24:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 620671 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p298NEsG007929 for ; Wed, 9 Mar 2011 08:23:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754645Ab1CIIXF (ORCPT ); Wed, 9 Mar 2011 03:23:05 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:50453 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1756795Ab1CIIXE (ORCPT ); Wed, 9 Mar 2011 03:23:04 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 5A65217013D; Wed, 9 Mar 2011 16:23:02 +0800 (CST) Received: from mailserver.fnst.cn.fujitus.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id p298H6cl006288; Wed, 9 Mar 2011 16:17:06 +0800 Received: from lai.fc14.fnst ([10.167.225.146]) by mailserver.fnst.cn.fujitus.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2011030916214844-320665 ; Wed, 9 Mar 2011 16:21:48 +0800 Message-ID: <4D773943.60803@cn.fujitsu.com> Date: Wed, 09 Mar 2011 16:24:35 +0800 From: Lai Jiangshan User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc14 Thunderbird/3.1.4 MIME-Version: 1.0 To: Luiz Capitulino CC: Markus Armbruster , Anthony Liguori , Lai Jiangshan , kvm@vger.kernel.org, qemu-devel@nongnu.org, Avi Kivity Subject: [PATCH V2] qemu,qmp: add keydown and keyup command for qmp X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-03-09 16:21:48, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-03-09 16:21:49, Serialize complete at 2011-03-09 16:21:49 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 09 Mar 2011 08:23:32 +0000 (UTC) diff --git a/monitor.c b/monitor.c index 22ae3bb..725df83 100644 --- a/monitor.c +++ b/monitor.c @@ -1810,16 +1810,25 @@ static uint8_t keycodes[MAX_KEYCODES]; static int nb_pending_keycodes; static QEMUTimer *key_timer; -static void release_keys(void *opaque) +static void keydown(uint8_t keycode) { - int keycode; + if (keycode & 0x80) + kbd_put_keycode(0xe0); + kbd_put_keycode(keycode & 0x7f); +} +static void keyup(uint8_t keycode) +{ + if (keycode & 0x80) + kbd_put_keycode(0xe0); + kbd_put_keycode(keycode | 0x80); +} + +static void release_keys(void *opaque) +{ while (nb_pending_keycodes > 0) { nb_pending_keycodes--; - keycode = keycodes[nb_pending_keycodes]; - if (keycode & 0x80) - kbd_put_keycode(0xe0); - kbd_put_keycode(keycode | 0x80); + keyup(keycodes[nb_pending_keycodes]); } } @@ -1866,17 +1875,41 @@ static void do_sendkey(Monitor *mon, const QDict *qdict) } nb_pending_keycodes = i; /* key down events */ - for (i = 0; i < nb_pending_keycodes; i++) { - keycode = keycodes[i]; - if (keycode & 0x80) - kbd_put_keycode(0xe0); - kbd_put_keycode(keycode & 0x7f); - } + for (i = 0; i < nb_pending_keycodes; i++) + keydown(keycodes[i]); /* delayed key up events */ qemu_mod_timer(key_timer, qemu_get_clock(vm_clock) + muldiv64(get_ticks_per_sec(), hold_time, 1000)); } +static int qmp_keyaction(const QDict *qdict, int down) +{ + int keycode = qdict_get_int(qdict, "keycode"); + + if (keycode < 0 || keycode >= 256) { + qerror_report(QERR_INVALID_PARAMETER_VALUE, "keycode", + "a valid keycode"); + return -1; + } + + if (down) + keydown(keycode); + else + keyup(keycode); + + return 0; +} + +static int qmp_keydown(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + return qmp_keyaction(qdict, 1); +} + +static int qmp_keyup(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + return qmp_keyaction(qdict, 0); +} + static int mouse_button_state; static void do_mouse_move(Monitor *mon, const QDict *qdict) diff --git a/qmp-commands.hx b/qmp-commands.hx index df40a3d..4c449bb 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -338,6 +338,58 @@ Example: EQMP { + .name = "keydown", + .args_type = "keycode:i", + .params = "keycode", + .help = "press down a key", + .user_print = monitor_user_noop, + .mhandler.cmd_new = qmp_keydown, + }, + +SQMP +keydown +--- + +Press down a key. + +Arguments: + +- "keycode": the code of the key to press down (json-int) + +Example: + +-> { "execute": "keydown", "arguments": { "keycode": 16 } } +<- { "return": {} } + +EQMP + + { + .name = "keyup", + .args_type = "keycode:i", + .params = "keycode", + .help = "release a key", + .user_print = monitor_user_noop, + .mhandler.cmd_new = qmp_keyup, + }, + +SQMP +keyup +--- + +Release a key. + +Arguments: + +- "keycode": the code of the key to release (json-int) + +Example: + +-> { "execute": "keyup", "arguments": { "keycode": 16 } } +<- { "return": {} } + +EQMP + + { .name = "cpu", .args_type = "index:i", .params = "index",