Example #1
0
void XdoInjector::update()
{
    if(global)
    {
        int ix, iy;
        int screen = 0;
        xdo_get_mouse_location(xdo, &ix, &iy, &screen);
        xdo_get_viewport_dimensions(xdo, &width, &height, screen);
    }
    else
        xdo_get_window_size(xdo, selectedWindow, &width, &height);
}
Example #2
0
void XdoInjector::injectMouseAbsolute(float x, float y)
{
    int ix, iy;
    int screen = 0;
    xdo_get_mouse_location(xdo, &ix, &iy, &screen);
    ix = width * (x+1)/2;
    iy = height * (y+1)/2;
    if(global)
        xdo_move_mouse(xdo, ix, iy, screen);
    else
        xdo_move_mouse_relative_to_window(xdo, selectedWindow, ix, iy);
}
Example #3
0
void XdoInjector::getMousePosition(float *x, float *y)
{
    int ix, iy;
    int screen = 0;
    xdo_get_mouse_location(xdo, &ix, &iy, &screen);
    if(!global)
    {
        int wx, wy;
        xdo_get_window_location(xdo, selectedWindow, &wx, &wy, nullptr);
        ix -= wx;
        iy -= wy;
    }
    *x = (2*ix-width)/(float)width;
    *y = (2*iy-height)/(float)height;
}
int cmd_mousemove_relative(context_t *context) {
  int x, y;
  int ret = 0;
  char *cmd = *context->argv;
  int polar_coordinates = 0;
  int clear_modifiers = 0;
  int opsync = 0;
  int origin_x = -1, origin_y = -1;

  charcodemap_t *active_mods = NULL;
  int active_mods_n;
  int c;
  typedef enum {
    opt_unused, opt_help, opt_sync, opt_clearmodifiers, opt_polar
  } optlist_t;
  static struct option longopts[] = {
    { "help", no_argument, NULL, opt_help },
    { "sync", no_argument, NULL, opt_sync },
    { "polar", no_argument, NULL, opt_polar },
    { "clearmodifiers", no_argument, NULL, opt_clearmodifiers },
    { 0, 0, 0, 0 },
  };
  static const char *usage =
      "Usage: %s [options] <x> <y>\n"
      "-c, --clearmodifiers      - reset active modifiers (alt, etc) while typing\n"
      "-p, --polar               - Use polar coordinates. X as an angle, Y as distance\n"
      "--sync                    - only exit once the mouse has moved\n"
      "\n"
      "Using polar coordinate mode makes 'x' the angle (in degrees) and\n"
      "'y' the distance.\n"
      "\n"
      "If you want to use negative numbers for a coordinate, you'll need to\n"
      "invoke it this way (with the '--'):\n"
      "   %s -- -20 -15\n"
      "otherwise, normal usage looks like this:\n"
      "   %s 100 140\n";
  int option_index;

  while ((c = getopt_long_only(context->argc, context->argv, "+cph",
                               longopts, &option_index)) != -1) {
    switch (c) {
      case 'h':
      case opt_help:
        printf(usage, cmd, cmd, cmd);
        consume_args(context, context->argc);
        return EXIT_SUCCESS;
        break;
      case 'p':
      case opt_polar:
        polar_coordinates = 1;
        break;
      case opt_sync:
        opsync = 1;
        break;
      case 'c':
      case opt_clearmodifiers:
        clear_modifiers = 1;
        break;
      default:
        fprintf(stderr, usage, cmd, cmd, cmd);
        return EXIT_FAILURE;
    }
  }

  consume_args(context, optind);

  if (context->argc < 2) {
    fprintf(stderr, usage, cmd, cmd, cmd);
    fprintf(stderr, "You specified the wrong number of args (expected 2).\n");
    return EXIT_FAILURE;
  }

  x = atoi(context->argv[0]);
  y = atoi(context->argv[1]);
  consume_args(context, 2);

  /* Quit early if we don't have to move. */
  if (x == 0 && y == 0) {
    return EXIT_SUCCESS;
  }

  if (polar_coordinates) {
    /* The original request for polar support was that '0' degrees is up
     * and that rotation was clockwise, so 0 is up, 90 right, 180 down, 270
     * left. This conversion can be done with (360 - degrees) + 90 */
    double radians = ((360 - x) + 90) * (M_PI / 180);
    double distance = y;
    x = (cos(radians) * distance);

    /* Negative sin, since screen Y coordinates are descending, where cartesian
     * is ascending */
    y = (-sin(radians) * distance);
  }
 
  if (clear_modifiers) {
    xdo_get_active_modifiers(context->xdo, &active_mods, &active_mods_n);
    xdo_clear_active_modifiers(context->xdo, CURRENTWINDOW, active_mods, active_mods_n);
  }

  if (opsync) {
    xdo_get_mouse_location(context->xdo, &origin_x, &origin_y, NULL);
  }

  ret = xdo_move_mouse_relative(context->xdo, x, y);

  if (ret) {
    fprintf(stderr, "xdo_move_mouse_relative reported an error\n");
  } else {
    if (opsync) {
      /* Wait until the mouse moves away from its current position */
      xdo_wait_for_mouse_move_from(context->xdo, origin_x, origin_y);
    }
  }

  if (clear_modifiers) {
    xdo_set_active_modifiers(context->xdo, CURRENTWINDOW, active_mods, active_mods_n);
    free(active_mods);
  }

  return ret;
}
Example #5
0
int main(int argc, char* argv[]) {

  bool legacyClick = false;


  if (argc == 1) {
    std::cout << "No arguments passed.\nUSAGE: Sp2 [device ID] [-r]\n";
    exit(2);
  }
  else if (argc >= 2) 
    std::cout << "Choosing device: " << argv[1] << std::endl;
  
  if (argc == 3) {
    
    std::string arg = argv[2];


    if (arg == "-r") {
      std::cout << "Legacy right-click enabled.\n";
      legacyClick = true;
    }
    else {
      std::cout << "Unknown argument passed.\nUSAGE: Sp2 [device ID] [-r]\n";
      exit(2);
    }

  }
    
  
  
    



  int pings = 0;
  int rightClicks = 0;

  int Xpos;
  int Ypos;
  int screen;

  input keys(argv[1]); // Create input structure son

  int delay = 10000;

  xdo_t *xdo = xdo_new(NULL);

  bool sp = true;
  


  while(1) {

    keys.waitUntilChange(); //Wait until a new key is pressed (or depressed)

    
    while(keys.returnLastKey() == 64) { //While L_ALT is pressed

      if(sp) {
	xdo_click_window(xdo,CURRENTWINDOW,1);
	pings++;
	std::cout << "Ping #" << pings << "\n";
      }

      else {

	if (legacyClick == false) {

	  xdo_move_mouse(xdo,1500,950,0);
	  xdo_mouse_down(xdo,CURRENTWINDOW,1);
	  xdo_move_mouse(xdo,1920/2,1080/2,0);
	  xdo_mouse_up(xdo,CURRENTWINDOW,1);
	}
	
	else {
	  xdo_click_window(xdo,CURRENTWINDOW,2);
	}

	rightClicks++;

	if(legacyClick) 
	  std::cout << "Legacy click #" << rightClicks << std::endl;
	else
	  std::cout << "Right click #" << rightClicks << std::endl;


      }

      usleep(delay);
    }



    while(keys.returnLastKey() == 86) { //While + is pressed
      std::cout << "Delay = " << delay << std::endl;
      delay = delay + 100;
      usleep(5000);
    }



    while(keys.returnLastKey() == 82) { // While - is pressed

      if ((delay-100) >= 0) {
	std::cout << "Delay = " << delay << std::endl;
	delay = delay - 100;
      }
      else
	std::cout << "Cant have a negative delay!\n";

      usleep(5000);
    }



    if (keys.returnLastKey() == 63) {

      if(sp) {
	sp = false;
	std::cout << "Switched to KillCour.\n";
      }
      else
	std::cout << "Already switched to KillCour\n";

    }



    if (keys.returnLastKey() == 106) {

      if(sp)
	std::cout << "Already switched to SupaPing.\n";
      else {
	sp = true;
	std::cout << "Switched to SupaPing.\n";
      }
    }	

    if(keys.returnLastKey() == 84) { // NUM_5

      std::cout << "Popping Glyph!\n";

      xdo_get_mouse_location(xdo,&Xpos,&Ypos,&screen);

      xdo_move_mouse(xdo, 1885, 1000 + 80/2, screen);

      xdo_click_window(xdo,CURRENTWINDOW,1);

      xdo_move_mouse(xdo, Xpos, Ypos, screen);

    }

      


    //std::cout << keys.returnLastKey() << "\n";

    
  }
    
  return 0;
}