Exemple #1
0
void read_callback(int read_success)
{
	if(read_success) {
		//nunchuk_print_data(&nun);
		int x = nun.X-128;
		int y = nun.Y-128;
		if(abs(x) < 15) x = 0;
		if(abs(y) < 15) y = 0;
		//x = (int)((float)x/7.5f);
		//y = (int)((float)y/7.5f);
		send_rel_mouse(x, -y);
		if(nun.C && !last_nun.C) {
			send_key_press(BTN_LEFT);
		}
		if(!nun.C && last_nun.C) {
			send_key_release(BTN_LEFT);
		}
		if(nun.Z && !last_nun.Z) {
			send_key_press(BTN_RIGHT);
		}
		if(!nun.Z && last_nun.Z) {
			send_key_release(BTN_RIGHT);
		}
		send_report();
		last_nun = nun;

    if (y != 0 || x != 0) {
      double r = x*x + y*y, p = atan2(y, x) * 4 / M_PI - 0.5;
      const char *d = "RF";
      if (p > -4) d = "XR";
      if (p > -3) d = "RR";
      if (p > -2) d = "RX";
      if (p > -1) d = "FR";
      if (p >  0) d = "FX";
      if (p >  1) d = "FF";
      if (p >  2) d = "XF";
      if (p >  3) d = "RF";
      if (r > 6400) {
        lirc_send(d);
        return;
      }
    }
    lirc_send(brake);
	}
  else
    lirc_send(NULL);
}
Exemple #2
0
bool QHimePlatformInputContext::filterEvent(const QEvent* event)
{
    dbg("QHimePlatformInputContext::filterEvent\n");
    if (event->type() != QEvent::KeyPress && event->type() != QEvent::KeyRelease) {
        goto ret;
    }

    const QKeyEvent* keyEvent;
    keyEvent = static_cast<const QKeyEvent*>(event);
    quint32 keysym ;
    keysym = keyEvent->nativeVirtualKey();
    quint32  state;
    state = keyEvent->nativeModifiers();

    if (!inputMethodAccepted()) {
        goto ret;
    }

    QObject *input;
    input = qApp->focusObject();

    if (!input) {
        goto ret;
    }

    int result;
    if (event->type() == QEvent::KeyPress) {
        if (send_key_press(keysym, state)) {
            update_preedit();
            return true;
        }
    } else {
        char *rstr = NULL;
        result = hime_im_client_forward_key_release(hime_ch,   keysym, state, &rstr);
        if (rstr) {
            free(rstr);
        }

        if (result) {
            return true;
        }
    }

ret:
    return QPlatformInputContext::filterEvent(event);
}
Exemple #3
0
/*
 * 执行快捷键指令
 */
void exec_cmd_via_keys(int *keys)
{
	int *tmp_key = keys;
	Display *disp = NULL;

	setlocale(LC_ALL, "");

	if ( !(disp = XOpenDisplay(NULL)) ) {
		sys_err("Cannot open display...\n");
		return ;
	}
	sys_err("create display ok!\n");
	
	//activate_win();
	match_wid = get_active_window();
	if ( match_wid == (Window)0 ) {
		sys_err("match wid failed...\n");
		XCloseDisplay(disp);
		return;
	}

	/* 设置指定窗口为焦点 */
	XSetInputFocus(disp, match_wid, RevertToParent, CurrentTime);
	XFlush(disp);
	while ( XPending(disp) ) {}

	sys_err("set keys pressed...\n");
	for (; *tmp_key != 0; tmp_key++ ) {
		send_key_press( disp, match_wid, *tmp_key  );
	}

	//usleep(500);

	sys_err("set keys release...\n");
	tmp_key = keys;
	for (; *tmp_key != 0; tmp_key++ ) {
		send_key_release( disp, match_wid, *tmp_key );
	}

	XCloseDisplay(disp);
	match_wid = (Window)0;
}
Exemple #4
0
void QHimePlatformInputContext::commitPreedit()
{
    dbg("QHimePlatformInputContext::commitPreedit\n");
    // use this to flush
    int preedit_cursor_position=0;
    int sub_comp_len;
    char *str=NULL;
    HIME_PREEDIT_ATTR att[HIME_PREEDIT_ATTR_MAX_N];
    hime_im_client_get_preedit(hime_ch, &str, att, &preedit_cursor_position, &sub_comp_len);
    if (str) {
        if (strlen(str) > 0) {
            dbg("send enter to flush\n");
            send_key_press(0xff0d, 0); // Enter
        } else {
            dbg("empty string\n");
        }

        free(str);
        update_preedit();
    } else {
        dbg("no str\n");
    }
}