From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sx7wF-0007qT-Hx for qemu-devel@nongnu.org; Thu, 02 Aug 2012 22:48:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sx7wE-0001kl-Bl for qemu-devel@nongnu.org; Thu, 02 Aug 2012 22:48:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63150) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sx7wE-0001ke-3B for qemu-devel@nongnu.org; Thu, 02 Aug 2012 22:48:30 -0400 From: Amos Kong Date: Fri, 3 Aug 2012 10:48:41 +0800 Message-Id: <1343962122-26696-7-git-send-email-akong@redhat.com> In-Reply-To: <1343962122-26696-1-git-send-email-akong@redhat.com> References: <1343962122-26696-1-git-send-email-akong@redhat.com> Subject: [Qemu-devel] [PATCH v6 6/7] add functions to convert key/code to index of mapping table List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, Amos Kong , eblake@redhat.com, lcapitulino@redhat.com Those two help functions will return Q_KEY_CODE_MAX if the code/key is invalid. Signed-off-by: Amos Kong --- console.h | 5 +++++ input.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/console.h b/console.h index 4334db5..c702b23 100644 --- a/console.h +++ b/console.h @@ -6,6 +6,7 @@ #include "notify.h" #include "monitor.h" #include "trace.h" +#include "qapi-types.h" /* keyboard/mouse support */ @@ -397,4 +398,8 @@ static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires) /* curses.c */ void curses_display_init(DisplayState *ds, int full_screen); +/* input.c */ +int index_from_key(const char *key); +int index_from_keycode(int code); + #endif diff --git a/input.c b/input.c index 680d756..2518c15 100644 --- a/input.c +++ b/input.c @@ -183,6 +183,44 @@ static const int key_defs[] = { [Q_KEY_CODE_MAX] = 0, }; +int index_from_key(const char *key) +{ + int i, keycode; + char *endp; + + for (i = 0; QKeyCode_lookup[i] != NULL; i++) { + if (!strcmp(key, QKeyCode_lookup[i])) { + break; + } + } + + if (strstart(key, "0x", NULL)) { + keycode = strtoul(key, &endp, 0); + if (*endp == '\0' && keycode >= 0x01 && keycode <= 0xff) { + for (i = 0; i < Q_KEY_CODE_MAX; i++) { + if (keycode == key_defs[i]) { + break; + } + } + } + } + + /* Return Q_KEY_CODE_MAX if the key is invalid */ + return i; +} + +int index_from_keycode(int code) +{ + int i; + for (i = 0; i < Q_KEY_CODE_MAX; i++) { + if (key_defs[i] == code) { + break; + } + } + /* Return Q_KEY_CODE_MAX if the code is invalid */ + return i; +} + void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) { qemu_put_kbd_event_opaque = opaque; -- 1.7.1