Example #1
0
static void make_button(int button, int x, int y, XButtonEvent* xev)
{
	xev->type = ButtonPress;
	xev->display = dpy;
	xev->root = root;
	xev->subwindow = None;
	xev->time = fake_timestamp();
	xev->x = x;
	xev->y = y;
	xev->x_root = 1;
	xev->y_root = 1;
	xev->state = 0;
	xev->button = button;
	xev->same_screen = True;
}
Example #2
0
void sendkey(char *keyname,int x,int y,Window w,Window s)
{
  make_key(keyname ,x,y,(XKeyEvent*)&xev);
  xev.xkey.window=w;
  xev.xkey.subwindow=s;

  if (s) sendfocus(s,FocusIn);

  XSendEvent(dpy,w,True,KeyPressMask,&xev);
  xev.type = KeyRelease;
  usleep(2000);
  xev.xkey.time = fake_timestamp();
  if (s) sendfocus(s,FocusOut);
  XSendEvent(dpy,w,True,KeyReleaseMask,&xev);
  XSync(dpy,True);
  return;
}
Example #3
0
void make_key(char *keyname,int x, int y,XKeyEvent *xev)
{
  char *part, *part2;
  struct keymodlist_t *kmlptr;
#ifndef HAVE_STRSEP
  char tmpkeyname[128];
  strncpy(tmpkeyname,keyname,128);
#endif
  part2=malloc(128);

  xev->type = KeyPress;
  xev->display=dpy;
  xev->root=root;
  xev->subwindow = None;
  xev->time=fake_timestamp();
  xev->x=x; xev->y=y;
  xev->x_root=1; xev->y_root=1;
  xev->same_screen = True;

  xev->state=0;
#ifdef HAVE_STRSEP
  while ((part=strsep(&keyname, key_delimiter)))
#else
  while ((part=strtok(tmpkeyname, key_delimiter)))
#endif
    {
      part2=strncpy(part2,part,128);
      //      debugprintf("-   %s \n",part);
      kmlptr=keymodlist;
      while (kmlptr->name)
	{
	  //	  debugprintf("--  %s %s \n", kmlptr->name, part);
	  if (!strcasecmp(kmlptr->name, part))
	    xev->state|=kmlptr->mask;
	  kmlptr++;
	}
      //      debugprintf("--- %s \n",part);
    } 
  //  debugprintf("*** %s \n",part);
  //  debugprintf("*** %s \n",part2);
  xev->keycode=XKeysymToKeycode(dpy,XStringToKeysym(part2));
  debugprintf("state 0x%x, keycode 0x%x\n",xev->state, xev->keycode);
  free(part2);
  return ;
}
Example #4
0
static void sendbutton(int button, int x, int y, Window w, Window s)
{
	make_button(button, x, y, (XButtonEvent*)&xev);
	xev.xbutton.window = w;
	xev.xbutton.subwindow = s;
	sendpointer_enter_or_leave(w, EnterNotify);
	sendpointer_enter_or_leave(s, EnterNotify);

	XSendEvent(dpy, w, True, ButtonPressMask, &xev);
	XSync(dpy, True);
	xev.type = ButtonRelease;
	xev.xkey.state |= 0x100;
	usleep(1000);
	xev.xkey.time = fake_timestamp();
	XSendEvent(dpy, w, True, ButtonReleaseMask, &xev);
	sendpointer_enter_or_leave(s, LeaveNotify);
	sendpointer_enter_or_leave(w, LeaveNotify);
	XSync(dpy, True);
}
Example #5
0
static void sendpointer_enter_or_leave(Window w, int in_out)
{
	XCrossingEvent crossev;

	crossev.type = in_out;
	crossev.display = dpy;
	crossev.window = w;
	crossev.root = root;
	crossev.subwindow = None;
	crossev.time = fake_timestamp();
	crossev.x = 1;
	crossev.y = 1;
	crossev.x_root = 1;
	crossev.y_root = 1;
	crossev.mode = NotifyNormal;
	crossev.detail = NotifyNonlinear;
	crossev.same_screen = True;
	crossev.focus = True;
	crossev.state = 0;
	XSendEvent(dpy, w, True, EnterWindowMask | LeaveWindowMask, (XEvent*)&crossev);
	XSync(dpy, True);
}
Example #6
0
static void make_key(char* keyname, int x, int y, XKeyEvent* xev)
{
	char* part;
	char* part2;
	char* sep_part;
	struct keymodlist_t* kmlptr;
	KeySym ks;
	KeyCode kc;

	part2 = (char*) malloc(128);

	xev->type = KeyPress;
	xev->display = dpy;
	xev->root = root;
	xev->subwindow = None;
	xev->time = fake_timestamp();
	xev->x = x;
	xev->y = y;
	xev->x_root = 1;
	xev->y_root = 1;
	xev->same_screen = True;

	xev->state = 0;
#ifdef HAVE_STRSEP
	while ((part = strsep(&keyname, key_delimiter)))
#else
	while ((part = strtok(keyname, key_delimiter)) && ((keyname = NULL) == NULL))
#endif
	{
		part2 = strncpy(part2, part, 128);
		//      log_debug("-   %s\n",part);
		kmlptr = keymodlist;
		while (kmlptr->name) {
			//      log_debug("--  %s %s\n", kmlptr->name, part);
			if (!strcasecmp(kmlptr->name, part))
				xev->state |= kmlptr->mask;
			kmlptr++;
		}
		//      log_debug("--- %s\n",part);
	}
	//  log_debug("*** %s\n",part);
	//  log_debug("*** %s\n",part2);

	/*
	 * New code 14-June-2005 by Warren Melnick, C.A.C. Media
	 * Uses the KeySym: and KeyCode: prefixes on the Key lines to allow for
	 * numeric keysym and keycode numbers to be used in place of X keysyms.
	 * Example 1: config = Key KeyCode:127 CurrentWindow
	 * Example 2: config = Key KeySym:0xFFF0 CurrentWindow
	 */
	ks = 0;
	kc = 0;
	if (strncmp(part2, "KeySym:", 7) == 0) {
		sep_part = part2 + 7;
		ks = strtoul(sep_part, NULL, 0);
		kc = XKeysymToKeycode(dpy, ks);
		log_debug("KeySym String: %s, KeySym: %ld KeyCode: %d\n", part2, ks, kc);
	} else if (strncmp(part2, "KeyCode:", 8) == 0) {
		sep_part = part2 + 8;
		kc = (KeyCode)strtoul(sep_part, NULL, 0);
		log_debug("KeyCode String: %s, KeyCode: %d\n", part2, kc);
	}
	if ((ks == 0) && (kc == 0)) {
		ks = XStringToKeysym(part2);
		kc = XKeysymToKeycode(dpy, ks);
		log_debug("Unmodified String: %s, KeySym: %d KeyCode: %d\n", part2, ks, kc);
	}
	xev->keycode = kc;
	log_debug("state 0x%x, keycode 0x%x\n", xev->state, xev->keycode);
	free(part2);
}