From: Ian Jackson Date: Sat, 6 Jun 2009 00:21:45 +0000 (+0100) Subject: keystroke injection attempts X-Git-Tag: 1.9.2~177 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.main.git;a=commitdiff_plain;h=d9d0cf7585c008aafe1d2de5365b772cda30ff13;ds=sidebyside keystroke injection attempts --- diff --git a/.gitignore b/.gitignore index 8875777..fd7f321 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ pctb/*.o pctb/t.* pctb/u.* pctb/convert +pctb/x-manip-window pctb/stuff/text.ppm pctb/stuff/text.png diff --git a/pctb/ls-xwindow-names b/pctb/ls-xwindow-names new file mode 100755 index 0000000..7fbbe40 --- /dev/null +++ b/pctb/ls-xwindow-names @@ -0,0 +1,36 @@ +#!/usr/bin/perl -w +use strict (qw(vars)); + +use IO::File; + +our @pipes; + +sub reap_pipe () { + my ($child, $pipe) = @{ shift @pipes }; + { local ($/) = undef; $_= <$pipe>; } + if (m/^WM_NAME: +not found/) { + } elsif (m/^WM_NAME\(STRING\) = $/) { + } elsif (m/^WM_NAME\(STRING\) = \"(.*)\"$/) { + print "$child $1\n" or die $!; + } else { + die "$child $_ ?"; + } + $!=0; $pipe->close(); $? and die "$? $! ?"; +} + +open WI, "LC_ALL=C xwininfo -root -children |" or die $!; +while () { + next unless m/^\s+\d+ children:/..0; + next unless m/^\s+(0x[0-9a-f]+) /; + my $child= $1; + + my $pipe= new IO::File "LC_ALL=C xprop -id $child WM_NAME |" or die $!; + push @pipes, [ $child, $pipe ]; + + while (@pipes > 40) { reap_pipe(); } +} +$!=0; close WI; $? and die "$? $! ?"; + +while (@pipes) { reap_pipe(); } + +close STDOUT or die $!; diff --git a/pctb/x-manip-window.c b/pctb/x-manip-window.c new file mode 100644 index 0000000..2ff1135 --- /dev/null +++ b/pctb/x-manip-window.c @@ -0,0 +1,69 @@ +/**/ + +#include +#include +#include + +#include + +#define eassert assert + +static Display *disp; +static long id; + +static void kmevent(XEvent *ev) { + int r; + r= XSendEvent(disp,id,False,0,ev); assert(r); +} + +static KeyCode keycode(const char *s) { + KeySym sym= XStringToKeysym(s); + return XKeysymToKeycode(disp,sym); +} + +int main(int argc, const char *const *argv) { + char *ep; + XWindowAttributes attr; + XEvent ev; + int r; + + id= strtoul(*++argv,&ep,0); + disp= XOpenDisplay(0); eassert(disp); + + r= XGetWindowAttributes(disp, id, &attr); eassert(r); + + while (*++argv) { + + memset(&ev,0,sizeof(ev)); +#define KE ev.xkey +#define ME ev.xbutton + + switch (**argv) { + case 'r': + r= XRaiseWindow(disp, id); eassert(r); + break; + +#define KMEVENT(e,t) \ + e.type= t; \ + e.window= id; \ + e.root= attr.root; \ + e.x= atoi(*++argv); \ + e.y= atoi(*++argv); \ + e.x_root= e.x; \ + e.y_root= e.y; \ + e.same_screen= True; \ + kmevent(&ev); \ + break; + + case 'K': KE.keycode= keycode(*++argv); KMEVENT(KE,KeyPress); + case 'k': KE.keycode= keycode(*++argv); KMEVENT(KE,KeyRelease); + case 'M': ME.button=1; KMEVENT(ME,ButtonPress); + case 'm': ME.button=1; ME.state=Button1Mask; KMEVENT(ME,ButtonRelease); + default: + abort(); + } + } + + r= XSync(disp, False); eassert(r); + exit(0); +}