direct-io.hg

changeset 7449:349d7b4ef7b0

Send special keys that your graphical user interface intercepts at
low level, such as ctrl-alt-del in X Window.

Adds a command "sendkey" to deal with it in the monitor, you
can send keys to the vm. Use - to press several keys simultaneously.
Example:
sendkey ctrl-alt-f1

Signed-off-by: Dan Xu <dan.d.xu@intel.com>
Signed-off-by: Zhai, Edwin <edwin.zhai@intel.com>
Signed-off-by: Xiaofeng Ling <xiaofeng.ling@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Oct 21 10:20:38 2005 +0100 (2005-10-21)
parents 19432bec4c06
children 349b302f29e2
files tools/ioemu/monitor.c
line diff
     1.1 --- a/tools/ioemu/monitor.c	Fri Oct 21 10:17:29 2005 +0100
     1.2 +++ b/tools/ioemu/monitor.c	Fri Oct 21 10:20:38 2005 +0100
     1.3 @@ -232,6 +232,161 @@ static void do_quit(void)
     1.4      exit(0);
     1.5  }
     1.6  
     1.7 +typedef struct {
     1.8 +    int keycode;
     1.9 +    const char *name;
    1.10 +} KeyDef;
    1.11 +
    1.12 +static const KeyDef key_defs[] = {
    1.13 +    { 0x2a, "shift" },
    1.14 +    { 0x36, "shift_r" },
    1.15 +    
    1.16 +    { 0x38, "alt" },
    1.17 +    { 0xb8, "alt_r" },
    1.18 +    { 0x1d, "ctrl" },
    1.19 +    { 0x9d, "ctrl_r" },
    1.20 +
    1.21 +    { 0xdd, "menu" },
    1.22 +
    1.23 +    { 0x01, "esc" },
    1.24 +
    1.25 +    { 0x02, "1" },
    1.26 +    { 0x03, "2" },
    1.27 +    { 0x04, "3" },
    1.28 +    { 0x05, "4" },
    1.29 +    { 0x06, "5" },
    1.30 +    { 0x07, "6" },
    1.31 +    { 0x08, "7" },
    1.32 +    { 0x09, "8" },
    1.33 +    { 0x0a, "9" },
    1.34 +    { 0x0b, "0" },
    1.35 +    { 0x0e, "backspace" },
    1.36 +
    1.37 +    { 0x0f, "tab" },
    1.38 +    { 0x10, "q" },
    1.39 +    { 0x11, "w" },
    1.40 +    { 0x12, "e" },
    1.41 +    { 0x13, "r" },
    1.42 +    { 0x14, "t" },
    1.43 +    { 0x15, "y" },
    1.44 +    { 0x16, "u" },
    1.45 +    { 0x17, "i" },
    1.46 +    { 0x18, "o" },
    1.47 +    { 0x19, "p" },
    1.48 +
    1.49 +    { 0x1c, "ret" },
    1.50 +
    1.51 +    { 0x1e, "a" },
    1.52 +    { 0x1f, "s" },
    1.53 +    { 0x20, "d" },
    1.54 +    { 0x21, "f" },
    1.55 +    { 0x22, "g" },
    1.56 +    { 0x23, "h" },
    1.57 +    { 0x24, "j" },
    1.58 +    { 0x25, "k" },
    1.59 +    { 0x26, "l" },
    1.60 +
    1.61 +    { 0x2c, "z" },
    1.62 +    { 0x2d, "x" },
    1.63 +    { 0x2e, "c" },
    1.64 +    { 0x2f, "v" },
    1.65 +    { 0x30, "b" },
    1.66 +    { 0x31, "n" },
    1.67 +    { 0x32, "m" },
    1.68 +    
    1.69 +    { 0x39, "spc" },
    1.70 +    { 0x3a, "caps_lock" },
    1.71 +    { 0x3b, "f1" },
    1.72 +    { 0x3c, "f2" },
    1.73 +    { 0x3d, "f3" },
    1.74 +    { 0x3e, "f4" },
    1.75 +    { 0x3f, "f5" },
    1.76 +    { 0x40, "f6" },
    1.77 +    { 0x41, "f7" },
    1.78 +    { 0x42, "f8" },
    1.79 +    { 0x43, "f9" },
    1.80 +    { 0x44, "f10" },
    1.81 +    { 0x45, "num_lock" },
    1.82 +    { 0x46, "scroll_lock" },
    1.83 +
    1.84 +    { 0x56, "<" },
    1.85 +
    1.86 +    { 0x57, "f11" },
    1.87 +    { 0x58, "f12" },
    1.88 +
    1.89 +    { 0xb7, "print" },
    1.90 +
    1.91 +    { 0xc7, "home" },
    1.92 +    { 0xc9, "pgup" },
    1.93 +    { 0xd1, "pgdn" },
    1.94 +    { 0xcf, "end" },
    1.95 +
    1.96 +    { 0xcb, "left" },
    1.97 +    { 0xc8, "up" },
    1.98 +    { 0xd0, "down" },
    1.99 +    { 0xcd, "right" },
   1.100 +
   1.101 +    { 0xd2, "insert" },
   1.102 +    { 0xd3, "delete" },
   1.103 +    { 0, NULL },
   1.104 +};
   1.105 +
   1.106 +static int get_keycode(const char *key)
   1.107 +{
   1.108 +    const KeyDef *p;
   1.109 +
   1.110 +    for(p = key_defs; p->name != NULL; p++) {
   1.111 +        if (!strcmp(key, p->name))
   1.112 +            return p->keycode;
   1.113 +    }
   1.114 +    return -1;
   1.115 +}
   1.116 +
   1.117 +static void do_send_key(const char *string)
   1.118 +{
   1.119 +    char keybuf[16], *q;
   1.120 +    uint8_t keycodes[16];
   1.121 +    const char *p;
   1.122 +    int nb_keycodes, keycode, i;
   1.123 +    
   1.124 +    nb_keycodes = 0;
   1.125 +    p = string;
   1.126 +    while (*p != '\0') {
   1.127 +        q = keybuf;
   1.128 +        while (*p != '\0' && *p != '-') {
   1.129 +            if ((q - keybuf) < sizeof(keybuf) - 1) {
   1.130 +                *q++ = *p;
   1.131 +            }
   1.132 +            p++;
   1.133 +        }
   1.134 +        *q = '\0';
   1.135 +        keycode = get_keycode(keybuf);
   1.136 +        if (keycode < 0) {
   1.137 +            term_printf("unknown key: '%s'\n", keybuf);
   1.138 +            return;
   1.139 +        }
   1.140 +        keycodes[nb_keycodes++] = keycode;
   1.141 +        if (*p == '\0')
   1.142 +            break;
   1.143 +        p++;
   1.144 +    }
   1.145 +    /* key down events */
   1.146 +    for(i = 0; i < nb_keycodes; i++) {
   1.147 +        keycode = keycodes[i];
   1.148 +        if (keycode & 0x80)
   1.149 +            kbd_put_keycode(0xe0);
   1.150 +        kbd_put_keycode(keycode & 0x7f);
   1.151 +    }
   1.152 +    /* key up events */
   1.153 +    for(i = nb_keycodes - 1; i >= 0; i--) {
   1.154 +        keycode = keycodes[i];
   1.155 +        if (keycode & 0x80)
   1.156 +            kbd_put_keycode(0xe0);
   1.157 +        kbd_put_keycode(keycode | 0x80);
   1.158 +    }
   1.159 +}
   1.160 +
   1.161 +
   1.162  static int eject_device(BlockDriverState *bs, int force)
   1.163  {
   1.164      if (bdrv_is_inserted(bs)) {
   1.165 @@ -331,6 +486,8 @@ static term_cmd_t term_cmds[] = {
   1.166        "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
   1.167      { "q|quit", "", do_quit,
   1.168        "", "quit the emulator" },
   1.169 +    { "sendkey", "s", do_send_key, 
   1.170 +      "keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" },
   1.171      { NULL, NULL, }, 
   1.172  };
   1.173