Example #1
0
void XdoInjector::injectKey(char c, bool up)
{
    const char s[2] = {c, 0};
    if(up)
        xdo_send_keysequence_window_up(xdo, global ? CURRENTWINDOW : selectedWindow, s, 0);
    else
        xdo_send_keysequence_window_down(xdo, global ? CURRENTWINDOW : selectedWindow, s, 0);
}
Example #2
0
void XdoInjector::injectKey(SpecialKey sk, bool up)
{
    const char* s = nullptr;
    for(auto m : mapping)
    {
        if(m.sk == sk)
            s = m.s;
    }
    if(up)
        xdo_send_keysequence_window_up(xdo, global ? CURRENTWINDOW : selectedWindow, s, 0);
    else
        xdo_send_keysequence_window_down(xdo, global ? CURRENTWINDOW : selectedWindow, s, 0);
}
Example #3
0
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];
		}
	}
}
Example #4
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;
	}
}
Example #5
0
void XDO::keyDown(const string& sequence) {
  xdo_send_keysequence_window_down(xdo_, CURRENTWINDOW, sequence.c_str(), 0);
}