示例#1
0
文件: tablet.c 项目: m-nez/pvp2005
void tablet_parse_data(tablet_t* t, unsigned char* data, xwrap_t* xw) {
	int i;
	static const char* keyseq[] = {"f", "f", "Control_L", "Shift_L"};
	uint8_t key_mask;
	if (data[0] == 0x1) { /* No pen */
		if ((data[2] & 0xA0) == 0xA0) { /* Buttons */
			if (t->prev_scroll != 0x0) {
				xdo_mouse_up(xw->xdo, CURRENTWINDOW, 2); /* Map middle mouse button to scroll */
				t->prev_scroll = 0x0;
			}
			for (i = 0; i < 4; ++i) {
				key_mask = 0x1 << i;
				if (t->prev_key_state & key_mask) { /* Key was already pressed */
					if ((key_mask & data[2]) == 0x0) { /* Now it is released */
						xdo_send_keysequence_window_up(xw->xdo, CURRENTWINDOW, keyseq[i], 0);
					}
				} else { /* Key was released */
					if (key_mask & data[2]) { /* Now it is pressed */
						xdo_send_keysequence_window_down(xw->xdo, CURRENTWINDOW, keyseq[i], 0);
					}
				}
			}
			t->prev_key_state = data[2];
		} else { /* Scroll */
			if (t->prev_scroll == 0x0) {
				xdo_mouse_down(xw->xdo, CURRENTWINDOW, 2); /* Map middle mouse button to scroll */
			}
			t->prev_scroll = data[2];
		}
	} else { /* Pen */
		if (data[1] != 0x0) { /* Pen is near the drawing plane */
			uint16_t x = reverse_bytes(*(uint16_t*)(data + 2));
			uint16_t y = reverse_bytes(*(uint16_t*)(data + 4));
			float fx = (float)x / t->horizontal_max;
			float fy = (float)y / t->vertical_max;

			xdo_move_mouse(xw->xdo, fx * xw->width, fy * xw->height, 0);

			check_button(0x01, 1, t->prev_point_state, data[1], xw); /* Left mouse button */
			check_button(0x02, 3, t->prev_point_state, data[1], xw); /* Right mouse button */
			t->prev_point_state = data[1];
		}
	}
}
示例#2
0
文件: tablet.c 项目: m-nez/pvp2005
static void check_button(
		unsigned char button_mask,
		int button,
		unsigned char prev_state,
		unsigned char cur_state,
		xwrap_t* xw
		) {
	if (prev_state & button_mask) {
		/* Button was already pressed */
		if ((cur_state & button_mask) == 0x0) {
			/* Now it is released */
			xdo_mouse_up(xw->xdo, CURRENTWINDOW, button);
		}
	} else {
		/* Button was released */
		if (cur_state & button_mask) {
			/* Now it is pressed */
			xdo_mouse_down(xw->xdo, CURRENTWINDOW, button);
		}
	}
}
示例#3
0
void mainloop(xdo_t* xdo, int joyfd, struct js_event* joystick, char jsbuttons, char jsaxes, char* buttons, char* axes, char* reversed, command* button_commands, command* axis_commands) {
	int last_value[jsaxes];
	char x;
	for (x = 0; x < jsaxes; ++x)
		last_value[x] = 0;

	char temp_axes[jsaxes];
	for (x = 0; x < jsaxes; ++x)
		temp_axes[axes[x]] = x;

	long delta[jsaxes];
	int sensitivity;
	while (1) {
		if (read(joyfd, joystick, sizeof(joystick)) < 0)
			syslog(LOG_ERR, "Failed to read from the joystick.");

		if (joystick->type == JS_EVENT_AXIS) {
			delta[joystick->number] = reversed[temp_axes[joystick->number]] * joystick->value - last_value[joystick->number];

			if (axis_commands[axes[joystick->number]].type == CMD_KEYPRESS) {
				if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "/HORIZONTAL") == 0) {
					if (joystick->value == 0) {
						if (delta[joystick->number] < 0)
							xdo_send_keysequence_window_up(xdo, CURRENTWINDOW, "Right", 0);
						else
							xdo_send_keysequence_window_up(xdo, CURRENTWINDOW, "Left", 0);
					} else if (joystick->value * reversed[temp_axes[joystick->number]] > 0)
						xdo_send_keysequence_window_down(xdo, CURRENTWINDOW, "Right", 0);
					else
						xdo_send_keysequence_window_down(xdo, CURRENTWINDOW, "Left", 0);

					if (reversed[temp_axes[joystick->number]] * joystick->value > 0 && delta[joystick->number] < 0 || reversed[temp_axes[joystick->number]] * joystick->value < 0 && delta[joystick->number] > 0)
						continue;
					else if (joystick->value == 0) {
						last_value[joystick->number] = 0;
						continue;
					} else {
						last_value[joystick->number] = reversed[temp_axes[joystick->number]] * joystick->value;
						continue;
					}
				} else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "/VERTICAL") == 0) {
					if (joystick->value == 0) {
						if (delta[joystick->number] < 0)
							xdo_send_keysequence_window_up(xdo, CURRENTWINDOW, "Up", 0);
						else
							xdo_send_keysequence_window_up(xdo, CURRENTWINDOW, "Down", 0);
					} else if (joystick->value * reversed[temp_axes[joystick->number]] > 0)
						xdo_send_keysequence_window_down(xdo, CURRENTWINDOW, "Up", 0);
					else
						xdo_send_keysequence_window_down(xdo, CURRENTWINDOW, "Down", 0);

					if (reversed[temp_axes[joystick->number]] * joystick->value > 0 && delta[joystick->number] < 0 || reversed[temp_axes[joystick->number]] * joystick->value < 0 && delta[joystick->number] > 0)
						continue;
					else if (joystick->value == 0) {
						last_value[joystick->number] = 0;
						continue;
					} else {
						last_value[joystick->number] = reversed[temp_axes[joystick->number]] * joystick->value;
						continue;
					}
				}
			}

			if (reversed[temp_axes[joystick->number]] * joystick->value > 0 && delta[joystick->number] < 0 || reversed[temp_axes[joystick->number]] * joystick->value < 0 && delta[joystick->number] > 0)
				continue;
			else if (joystick->value == 0) {
				last_value[joystick->number] = 0;
				continue;
			}

			switch (axis_commands[axes[joystick->number]].type) {
				case CMD_NONE:
				break;

				case CMD_MOUSEMOVE:
				sensitivity = atoi(axis_commands[joystick->number].arguments[1]);
				delta[joystick->number] = reversed[temp_axes[joystick->number]] * delta[joystick->number] * (delta[joystick->number] > 0 ? delta[joystick->number] : delta[joystick->number] * (-1)) * sensitivity / 1800000;
				if (strcmp(axis_commands[joystick->number].arguments[0], "horizontal") == 0)
					xdo_move_mouse_relative(xdo, delta[joystick->number], 0);
				else 
					xdo_move_mouse_relative(xdo, 0, delta[joystick->number]);
				break;

				case CMD_MOUSECLICK:
				if (strcmp(axis_commands[axes[joystick->number]].arguments[1], "current") == 0) {
					if (delta[joystick->number] > 0) {
						if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "left") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 1);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "middle") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 2);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "right") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 3);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "wheelup") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 4);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "wheeldown") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 5);
					} else {
						if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "left") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 1);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "middle") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 2);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "right") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 3);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "wheelup") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 4);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "wheeldown") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 5);
					}
				} else {
					int x = atoi(axis_commands[axes[joystick->number]].arguments[1]);
					int y = atoi(axis_commands[axes[joystick->number]].arguments[2]);
					int screen = atoi(axis_commands[axes[joystick->number]].arguments[3]);
					xdo_move_mouse(xdo, x, y, screen);
					if (delta[joystick->number] > 0) {
						if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "left") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 1);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "middle") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 2);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "right") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 3);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "wheelup") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 4);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "wheeldown") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 5);
					} else {
						if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "left") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 1);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "middle") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 2);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "right") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 3);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "wheelup") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 4);
						else if (strcmp(axis_commands[axes[joystick->number]].arguments[0], "wheeldown") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 5);
					}
				}
				break;

				case CMD_MOUSETELEPORT:
				if (delta[joystick->number] > 0) {
					int x = atoi(axis_commands[axes[joystick->number]].arguments[0]);
					int y = atoi(axis_commands[axes[joystick->number]].arguments[1]);
					int screen = atoi(axis_commands[axes[joystick->number]].arguments[2]);
					xdo_move_mouse(xdo, x, y, screen);
				}
				break;

				case CMD_KEYPRESS:

				if (delta[joystick->number] > 0)
					xdo_send_keysequence_window_down(xdo, CURRENTWINDOW, axis_commands[axes[joystick->number]].arguments[0], 0);
				else
					xdo_send_keysequence_window_up(xdo, CURRENTWINDOW, axis_commands[axes[joystick->number]].arguments[0], 0);
				break;

				case CMD_KEYSTROKE:
				if (delta[joystick->number] > 0)
					xdo_enter_text_window(xdo, CURRENTWINDOW, axis_commands[axes[joystick->number]].arguments[0], 0);
				break;

				case CMD_COMMAND:
				if (delta[joystick->number] > 0)
					system(axis_commands[axes[joystick->number]].arguments[0]);
				break;

				default:
				break;
			}
		} else if (joystick->type == JS_EVENT_BUTTON) {
			switch (button_commands[buttons[joystick->number]].type) {
				case CMD_NONE:
				break;

				case CMD_MOUSECLICK:
				if (strcmp(button_commands[buttons[joystick->number]].arguments[1], "current") == 0) {
					if (joystick->value == 1) {
						if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "left") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 1);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "middle") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 2);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "right") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 3);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "wheelup") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 4);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "wheeldown") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 5);
					} else {
						if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "left") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 1);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "middle") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 2);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "right") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 3);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "wheelup") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 4);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "wheeldown") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 5);
					}
				} else {
					int x = atoi(button_commands[buttons[joystick->number]].arguments[1]);
					int y = atoi(button_commands[buttons[joystick->number]].arguments[2]);
					int screen = atoi(button_commands[buttons[joystick->number]].arguments[3]);
					xdo_move_mouse(xdo, x, y, screen);
					if (joystick->value == 1) {
						if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "left") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 1);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "middle") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 2);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "right") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 3);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "wheelup") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 4);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "wheeldown") == 0)
							xdo_mouse_down(xdo, CURRENTWINDOW, 5);
					} else {
						if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "left") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 1);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "middle") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 2);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "right") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 3);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "wheelup") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 4);
						else if (strcmp(button_commands[buttons[joystick->number]].arguments[0], "wheeldown") == 0)
							xdo_mouse_up(xdo, CURRENTWINDOW, 5);
					}
				}
				break;

				case CMD_MOUSETELEPORT:
				if (joystick->value == 1) {
					int x = atoi(button_commands[buttons[joystick->number]].arguments[0]);
					int y = atoi(button_commands[buttons[joystick->number]].arguments[1]);
					int screen = atoi(button_commands[buttons[joystick->number]].arguments[2]);
					xdo_move_mouse(xdo, x, y, screen);
				}
				break;

				case CMD_KEYPRESS:
				if (joystick->value == 1)
					xdo_send_keysequence_window_down(xdo, CURRENTWINDOW, button_commands[buttons[joystick->number]].arguments[0], 0);
				else
					xdo_send_keysequence_window_up(xdo, CURRENTWINDOW, button_commands[buttons[joystick->number]].arguments[0], 0);
				break;

				case CMD_KEYSTROKE:
				if (joystick->value == 1)
					xdo_enter_text_window(xdo, CURRENTWINDOW, button_commands[buttons[joystick->number]].arguments[0], 0);
				break;

				case CMD_COMMAND:
				if (joystick->value == 1)
					system(button_commands[buttons[joystick->number]].arguments[0]);
				break;

				default:
				break;
			}
		}

		last_value[joystick->number] = reversed[temp_axes[joystick->number]] * joystick->value;
	}
}
示例#4
0
文件: xdo.cpp 项目: kallaballa/Janosh
void XDO::mouseDown(int button) {
  xdo_mouse_down(xdo_, CURRENTWINDOW, button);
}
示例#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;
}