From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K5UJv-0007py-Ei for qemu-devel@nongnu.org; Sun, 08 Jun 2008 19:29:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K5UJu-0007pF-Np for qemu-devel@nongnu.org; Sun, 08 Jun 2008 19:29:07 -0400 Received: from [199.232.76.173] (port=57266 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K5UJu-0007p6-Aa for qemu-devel@nongnu.org; Sun, 08 Jun 2008 19:29:06 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]:51885) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K5UJu-0003bU-JI for qemu-devel@nongnu.org; Sun, 08 Jun 2008 19:29:06 -0400 Received: from smtp08.web.de (fmsmtp08.dlan.cinetic.de [172.20.5.216]) by fmmailgate01.web.de (Postfix) with ESMTP id D2F78E35B220 for ; Mon, 9 Jun 2008 01:29:04 +0200 (CEST) Received: from [88.65.38.31] (helo=[192.168.1.198]) by smtp08.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.109 #226) id 1K5UJs-0001Kj-00 for qemu-devel@nongnu.org; Mon, 09 Jun 2008 01:29:04 +0200 Message-ID: <484C6B40.1070601@web.de> Date: Mon, 09 Jun 2008 01:29:04 +0200 From: Jan Kiszka MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Sender: jan.kiszka@web.de Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Re: [4701] Enhance sendkey with key hold time (Jan Kiszka). Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Andrzej Zaborowski wrote: > Revision: 4701 > http://svn.sv.gnu.org/viewvc/?view=3Drev&root=3Dqemu&revision= =3D4701 > Author: balrog > Date: 2008-06-08 22:45:01 +0000 (Sun, 08 Jun 2008) >=20 > Log Message: > ----------- > Enhance sendkey with key hold time (Jan Kiszka). >=20 > Current key injection via the monitor basically generates no key hold > time. This is fine for keyboard emulations that have their own queues, > but it causes troubles for those how don't (like the MusicPal - it > simply does not work with injected keys). Moreover, I would like to use > this mechanism to simulate pressed buttons during power-up. >=20 > Therefore, this patch enhances the key injection with a configurable > release delay (by default 100 virtual milliseconds). >=20 > This feature allows to get rid of the initial sleep() in musicpal_init > because one can now simply start qemu with -S and issue "sendkey m 1000= " > and "continue" in the monitor to achieve the desired effect of a presse= d > menu button during power-up. So there is no need for a per-musicpal or > even qemu-wide "-hold-button" switch. >=20 > Signed-off-by: Jan Kiszka >=20 > Modified Paths: > -------------- > trunk/hw/musicpal.c > trunk/monitor.c >=20 > Modified: trunk/hw/musicpal.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- trunk/hw/musicpal.c 2008-06-08 07:42:23 UTC (rev 4700) > +++ trunk/hw/musicpal.c 2008-06-08 22:45:01 UTC (rev 4701) > @@ -1504,12 +1504,6 @@ > =20 > qemu_add_kbd_event_handler(musicpal_key_event, pic[MP_GPIO_IRQ]); > =20 > - /* > - * Wait a bit to catch menu button during U-Boot start-up > - * (to trigger emergency update). > - */ > - sleep(1); > - > mv88w8618_eth_init(&nd_table[0], MP_ETH_BASE, pic[MP_ETH_IRQ]); > =20 > mixer_i2c =3D musicpal_audio_init(MP_AUDIO_BASE, pic[MP_AUDIO_IRQ]= ); >=20 > Modified: trunk/monitor.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- trunk/monitor.c 2008-06-08 07:42:23 UTC (rev 4700) > +++ trunk/monitor.c 2008-06-08 22:45:01 UTC (rev 4701) > @@ -35,11 +35,8 @@ > #include "audio/audio.h" > #include "disas.h" > #include > +#include "qemu-timer.h" > =20 > -#ifdef CONFIG_PROFILER > -#include "qemu-timer.h" /* for ticks_per_sec */ > -#endif > - > //#define DEBUG > //#define DEBUG_COMPLETION > =20 > @@ -920,14 +917,37 @@ > return -1; > } > =20 > -static void do_sendkey(const char *string) > +#define MAX_KEYCODES 16 > +static uint8_t keycodes[MAX_KEYCODES]; > +static int nb_pending_keycodes; > +static QEMUTimer *key_timer; > + > +static void release_keys(void *opaque) > { > - uint8_t keycodes[16]; > - int nb_keycodes =3D 0; > + int keycode; > + > + while (nb_pending_keycodes > 0) { > + nb_pending_keycodes--; > + keycode =3D keycodes[nb_pending_keycodes]; > + if (keycode & 0x80) > + kbd_put_keycode(0xe0); > + kbd_put_keycode(keycode | 0x80); > + } > +} > + > +static void do_sendkey(const char *string, int has_hold_time, int hold= _time) > +{ > char keyname_buf[16]; > char *separator; > int keyname_len, keycode, i; > =20 > + if (nb_pending_keycodes > 0) { > + qemu_del_timer(key_timer); > + release_keys(NULL); > + } > + if (!has_hold_time) > + hold_time =3D 100; > + i =3D 0; > while (1) { > separator =3D strchr(string, '-'); > keyname_len =3D separator ? separator - string : strlen(string= ); > @@ -937,7 +957,7 @@ > term_printf("invalid key: '%s...'\n", keyname_buf); > return; > } > - if (nb_keycodes =3D=3D sizeof(keycodes)) { > + if (i =3D=3D MAX_KEYCODES) { > term_printf("too many keys\n"); > return; > } > @@ -947,26 +967,23 @@ > term_printf("unknown key: '%s'\n", keyname_buf); > return; > } > - keycodes[nb_keycodes++] =3D keycode; > + keycodes[i++] =3D keycode; > } > if (!separator) > break; > string =3D separator + 1; > } > + nb_pending_keycodes =3D i; > /* key down events */ > - for(i =3D 0; i < nb_keycodes; i++) { > + for (i =3D 0; i < nb_pending_keycodes; i++) { > keycode =3D keycodes[i]; > if (keycode & 0x80) > kbd_put_keycode(0xe0); > kbd_put_keycode(keycode & 0x7f); > } > - /* key up events */ > - for(i =3D nb_keycodes - 1; i >=3D 0; i--) { > - keycode =3D keycodes[i]; > - if (keycode & 0x80) > - kbd_put_keycode(0xe0); > - kbd_put_keycode(keycode | 0x80); > - } > + /* delayed key up events */ > + qemu_mod_timer(key_timer, > + qemu_get_clock(vm_clock) + ticks_per_sec * hold_tim= e); Damn. That should have been: Index: monitor.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- monitor.c (Revision 4701) +++ monitor.c (Arbeitskopie) @@ -983,7 +983,7 @@ static void do_sendkey(const char *strin } /* delayed key up events */ qemu_mod_timer(key_timer, - qemu_get_clock(vm_clock) + ticks_per_sec * hold_time)= ; + qemu_get_clock(vm_clock) + ticks_per_sec/1000 * hold_= time); } =20 static int mouse_button_state; [ hold_time is in milliseconds. ] Please merge. Jan