From: Amos Kong <akong@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, Amos Kong <akong@redhat.com>,
eblake@redhat.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH v6 6/7] add functions to convert key/code to index of mapping table
Date: Fri, 3 Aug 2012 10:48:41 +0800 [thread overview]
Message-ID: <1343962122-26696-7-git-send-email-akong@redhat.com> (raw)
In-Reply-To: <1343962122-26696-1-git-send-email-akong@redhat.com>
Those two help functions will return Q_KEY_CODE_MAX
if the code/key is invalid.
Signed-off-by: Amos Kong <akong@redhat.com>
---
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
next prev parent reply other threads:[~2012-08-03 2:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-03 2:48 [Qemu-devel] [PATCH v6 0/7] convert sendkey to qapi Amos Kong
2012-08-03 2:48 ` [Qemu-devel] [PATCH v6 1/7] fix doc of using raw values with sendkey Amos Kong
2012-08-03 2:48 ` [Qemu-devel] [PATCH v6 2/7] monitor: rename keyname '<' to 'less' Amos Kong
2012-08-03 2:48 ` [Qemu-devel] [PATCH v6 3/7] hmp: rename arguments Amos Kong
2012-08-03 2:48 ` [Qemu-devel] [PATCH v6 4/7] qapi: generate list struct and visit_list for enum Amos Kong
2012-08-03 2:48 ` [Qemu-devel] [PATCH v6 5/7] add the QKeyCode enum and the key_defs table Amos Kong
2012-08-03 13:32 ` Luiz Capitulino
2012-08-03 18:00 ` Andreas Färber
2012-08-03 20:32 ` Luiz Capitulino
2012-08-13 8:50 ` Amos Kong
2012-08-03 2:48 ` Amos Kong [this message]
2012-08-03 2:48 ` [Qemu-devel] [PATCH v6 7/7] qapi: convert sendkey Amos Kong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343962122-26696-7-git-send-email-akong@redhat.com \
--to=akong@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=eblake@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).