Пример кода с использованием XSendEvent (x example)
Ключевые слова: x, example, (найти похожие документы)
- BEST_PEOPLE (2:5077/15.22) ------------------------- BEST_PEOPLE (RU.LINUX) -
From : Yuriy Kaminskiy 2:5020/517.21 24 Feb 01 20:19:08
Subj : Пример кода с использованием XSendEvent
-------------------------------------------------------------------------------
* Forwarded from area 'RU.LINUX'
MI> А можно кусок кода на tcl/python/C с использованием XSendEvent?
MI> А то я в Xlib не силен.
Hу вот, на коленке сбацал; работает, однако:
/*
* compile & link: gcc -pipe -O2 -o xsendevent{,.c} -L /usr/X11R6/lib -lX11
* run: ./xsendevent "$WINDOWID" 1 2 3 4 Left
* # sends keys 1, 2, 3, 4 and Left to window $WINDOWID
*/
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <string.h>
int main(int argc, char *argv[])
{
Display *dpy;
Window window;
char *prog;
char *s;
int i;
if ((prog=strrchr(argv[0],'/'))==NULL)
prog=argv[0];
else
prog++;
if (argc < 2) {
printf("Usage: %s windowid\n", prog);
return 1;
}
dpy = XOpenDisplay(NULL);
if (dpy == NULL) {
fprintf(stderr,"%s: Cannot open display\n",prog);
return 1;
}
window = (Window)strtol(argv[1], &s, 0);
if(*s) {
fprintf(stderr, "%s: bad windowid: `%s'\n%*c\n",
prog,argv[1],strlen(prog)+17+1+(s-argv[1]),'^');
XCloseDisplay(dpy);
return 1;
}
for(i = 2; i < argc; i++) {
XEvent ev;
KeySym key;
ev.xkey.type = KeyPress;
ev.xkey.window = window;
ev.xkey.root = ev.xkey.subwindow = None;
ev.xkey.time = 0;
ev.xkey.x = ev.xkey.y = ev.xkey.x_root = ev.xkey.y_root = 0;
ev.xkey.state = 0;
key = XStringToKeysym(argv[i]);
ev.xkey.keycode = XKeysymToKeycode(dpy,key);
ev.xkey.same_screen = True;
XSendEvent(dpy, window, True, KeyPressMask, &ev);
ev.type = KeyRelease;
XSendEvent(dpy, window, True, KeyReleaseMask, &ev);
}
XCloseDisplay(dpy);
return 0;
}
/* vim: aw
*/
--
Yuriy Kaminskiy.
--Multipart_Sat_Feb_24_20:19:08_2001-1--
--- Gnus v5.2.25/XEmacs 19.14
* Origin: Kyle Katan's station (2:5020/517.21@fidonet)