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

int xdo_keysequence_list_do ( const xdo_t xdo,
Window  window,
charcodemap_t keys,
int  nkeys,
int  pressed,
int *  modifier,
useconds_t  delay 
)

Send a series of keystrokes.

Parameters:
window The window to send events to or CURRENTWINDOW
keys The array of charcodemap_t entities to send.
nkeys The length of the keys parameter
pressed 1 for key press, 0 for key release.
modifier Pointer to integer to record the modifiers activated by the keys being pressed. If NULL, we don't save the modifiers.
delay The delay between keystrokes in microseconds.

Definition at line 845 of file xdo.c.

References charcodemap::code, xdo::keycode_low, charcodemap::symbol, and xdo::xdpy.

                                                                                     {
  int i = 0;
  int modstate = 0;
  int keymapchanged;

  /* Find an unused keycode in case we need to bind unmapped keysyms */
  KeySym *keysyms = NULL;
  int keysyms_per_keycode = 0;
  int scratch_keycode = 0; /* Scratch space for temporary keycode bindings */
  //keysyms = XGetKeyboardMapping(xdo->xdpy, xdo->keycode_low, 
                                //xdo->keycode_high - xdo->keycode_low,
                                //&keysyms_per_keycode);
  /* Find a keycode that is unused for scratchspace */
  for (i = xdo->keycode_low; i <= xdo->keycode_high; i++) {
    int j = 0;
    int key_is_empty = 1;
    for (j = 0; j < keysyms_per_keycode; j++) {
      char *symname;
      int symindex = (i - xdo->keycode_low) * keysyms_per_keycode + j;
      symname = XKeysymToString(keysyms[symindex]);
      if (keysyms[symindex] != 0) {
        key_is_empty = 0;
      }
    }
    if (key_is_empty) {
      scratch_keycode = i;
      break;
    }
  }
  XFree(keysyms);

  /* Allow passing NULL for modifier in case we don't care about knowing
   * the modifier map state after we finish */
  if (modifier == NULL)
    modifier = &modstate;

  for (i = 0; i < nkeys; i++) {
    if (keys[i].needs_binding == 1) {
      KeySym keysym_list[] = { keys[i].symbol };
      //fprintf(stderr, "Mapping sym %lu to %d\n", keys[i].symbol, scratch_keycode);
      XChangeKeyboardMapping(xdo->xdpy, scratch_keycode, 1, keysym_list, 1);
      /* override the code in our current key to use the scratch_keycode */
      keys[i].code = scratch_keycode;
      keymapchanged = 1;
    }

    //fprintf(stderr, "Sending %c (%d, mods %x)\n", keys[i].key, keys[i].code, *modifier);
    _xdo_send_key(xdo, window, &(keys[i]), *modifier, pressed, delay);

    if (keys[i].needs_binding == 1) {
      /* If we needed to make a new keymapping for this keystroke, we
       * should sync with the server now, after the keypress, so that
       * the next mapping or removal doesn't conflict. */
      XSync(xdo->xdpy, False);
    }

    if (pressed) {
      *modifier |= _xdo_cached_keycode_to_modifier(xdo, keys[i].code);
    } else {
      *modifier &= ~(_xdo_cached_keycode_to_modifier(xdo, keys[i].code));
    }
  }


  if (keymapchanged) {
    KeySym keysym_list[] = { 0 };
    XChangeKeyboardMapping(xdo->xdpy, scratch_keycode, 1, keysym_list, 1);
  }

  /* Necessary? */
  XFlush(xdo->xdpy);
  return XDO_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index