Logo Search packages:      
Sourcecode: xdotool version File versions  Download package

int xdo_type ( const xdo_t xdo,
Window  window,
char *  string,
useconds_t  delay 
)

Type a string to the specified window.

If you want to send a specific key or key sequence, such as "alt+l", you want instead xdo_keysequence.

Parameters:
window The window you want to send keystrokes to or CURRENTWINDOW
string The string to type, like "Hello world!"
delay The delay between keystrokes in microseconds. 12000 is a decent choice if you don't have other plans.

Definition at line 747 of file xdo.c.

References charcodemap::code, charcodemap::index, xdo_active_mods::input_state, charcodemap::key, charcodemap::modmask, charcodemap::needs_binding, and charcodemap::symbol.

                                                                              {
  int i = 0;
  //char key = '\0';
  //XXX: REMOVE //int keycode = 0;
  //TODO(sissel): REMOVE //int key_index = 0;

  /* Since we're doing down/up, the delay should be based on the number
   * of keys pressed (including shift). Since up/down is two calls,
   * divide by two. */
  delay /= 2;

  xdo_active_mods_t *current_mods = xdo_get_active_modifiers(xdo);
  /* XXX: Add error handling */
  //int nkeys = strlen(string);
  //charcodemap_t *keys = calloc(nkeys, sizeof(charcodemap_t));
  charcodemap_t key;
  //int modifier = 0;
  for (i = 0; string[i] != '\0'; i++) {
    key.key = string[i];
    key.code = _xdo_keycode_from_char(xdo, key.key);
    key.symbol = _xdo_keysym_from_char(xdo, key.key);
    key.modmask = 0;
    key.needs_binding = 0;
    if (key.code == 0 && key.symbol == NoSymbol) {
      fprintf(stderr, "I don't what key produces '%c', skipping.\n",
              key.key);
      continue;
    }

    if (key.code > 0) {
      key.index = _xdo_get_key_index(xdo, key.key);
    } else {
      key.needs_binding = 1;
    }

    /* I don't know how to type keys beyond key group 1 or 2 (index 4 and
     * beyond). Index 4 and 5 are suppsedly means numlock is set. However,
     * simply sending the Num_Lock key doesn't seem to work. We can work
     * around this by binding a new key to the key and using that. */
    if (key.index >= 4) {
      key.needs_binding = 1;
      //key.index = 0;
    }

    if (key.needs_binding == 0) {
      if (key.index & 1) { /* odd numbered index are shifted */
        //printf("Using ShiftMask\n");
        key.modmask |= ShiftMask;
      }
      /* Keys with index 2 and 3 are accessed with Mode_switch key, which is 
       * defaults to Mod5Mask */
      if ((current_mods->input_state & ModeSwitchMask) == 0) {
        if (key.index == 2 || key.index == 3) {
          //printf("Using Mod5Mask\n");
          key.modmask |= Mod5Mask; /* Set AltG/Mode_Shift */
        }
      } 
    }


    //printf(stderr,
            //"Key '%c' maps to code %d / sym %lu with index %d / mods %d (%s)\n",
            //key.key, key.code, key.symbol, key.index, key.modmask, 
            //(key.needs_binding == 1) ? "needs binding" : "ok");

    //_xdo_send_key(xdo, window, keycode, modstate, True, delay);
    //_xdo_send_key(xdo, window, keycode, modstate, False, delay);
    xdo_keysequence_list_do(xdo, window, &key, 1, True, NULL, delay / 2);
    xdo_keysequence_list_do(xdo, window, &key, 1, False, NULL, delay / 2);

    /* XXX: Flush here or at the end? or never? */
    //XFlush(xdo->xdpy);
  } /* walk string generating a keysequence */

  //free(keys);
  xdo_free_active_modifiers(current_mods);
  return XDO_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index