1#!/usr/bin/perl
2
3# This is a test injection script for Linux uinput.
4# It can be handy working out / troubleshooting Linux uinput injection on a new device.
5
6#
7# Copyright (c) 2010 by Karl J. Runge <runge@karlrunge.com>
8#
9# uinput.pl is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or (at
12# your option) any later version.
13#
14# uinput.pl is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with uinput.pl; if not, write to the Free Software
21# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
22# or see <http://www.gnu.org/licenses/>.
23#
24
25set_constants();
26
27# options for what injection to handle:
28$rel = 1;
29$abs = 1;
30$touch = 1;
31$allkeys = 1;
32
33# these can be set via env:
34
35$WIDTH  = $ENV{WIDTH};
36$WIDTH  = 480 unless $WIDTH;
37$HEIGHT = $ENV{HEIGHT};
38$HEIGHT = 640 unless $HEIGHT;
39$DEV = $ENV{DEV};
40$DEV = "/dev/input/uinput" unless $DEV;
41
42# this fills in name and input type part of uinput_user_dev struct:
43
44$udev = "uinput.pl";
45$n = 80 - length($udev);
46$udev .= "\0" x $n;
47
48$udev .= "\0" x 2;	# bus
49$udev .= "\0" x 2;	# vendor
50$udev .= "\0" x 2;	# product
51$udev .= "\0" x 2;	# version
52
53$udev .= "\0" x 4;	# ff_effects_max
54
55# this fills in the abs arrays:
56#
57foreach $type (qw(absmax absmin absfuzz absflat))  {
58	$n = $ABS_MAX + 1;
59	for ($j = 0; $j < $n; $j++) {
60		if ($abs && $type eq 'absmax' && $j == $ABS_X) {
61			$udev .= pack("i", $WIDTH-1);
62		} elsif ($abs && $type eq 'absmax' && $j == $ABS_Y) {
63			$udev .= pack("i", $HEIGHT-1);
64		} else {
65			$udev .= "\0" x 4;
66		}
67	}
68}
69
70print "udev: ", length($udev) . " '$udev'\n";
71
72$modes = $O_RDWR;
73$modes = $O_WRONLY | $O_NDELAY;
74printf("open modes: 0x%x\n", $modes);
75
76sysopen(FD, $DEV, $modes) || die "$DEV: $!";
77
78if ($rel) {
79	io_ctl($UI_SET_EVBIT,  $EV_REL);
80	io_ctl($UI_SET_RELBIT, $REL_X);
81	io_ctl($UI_SET_RELBIT, $REL_Y);
82}
83
84io_ctl($UI_SET_EVBIT, $EV_KEY);
85
86io_ctl($UI_SET_EVBIT, $EV_SYN);
87
88for ($i=0; $i < 256; $i++) {
89	last unless $allkeys;
90	io_ctl($UI_SET_KEYBIT, $i);
91}
92
93io_ctl($UI_SET_KEYBIT, $BTN_MOUSE);
94io_ctl($UI_SET_KEYBIT, $BTN_LEFT);
95io_ctl($UI_SET_KEYBIT, $BTN_MIDDLE);
96io_ctl($UI_SET_KEYBIT, $BTN_RIGHT);
97io_ctl($UI_SET_KEYBIT, $BTN_FORWARD);
98io_ctl($UI_SET_KEYBIT, $BTN_BACK);
99
100if ($abs) {
101	io_ctl($UI_SET_KEYBIT, $BTN_TOUCH) if $touch;
102	io_ctl($UI_SET_EVBIT,  $EV_ABS);
103	io_ctl($UI_SET_ABSBIT, $ABS_X);
104	io_ctl($UI_SET_ABSBIT, $ABS_Y);
105}
106
107$ret = syswrite(FD, $udev, length($udev));
108print "syswrite: $ret\n";
109
110io_ctl($UI_DEV_CREATE);
111fsleep(0.25);
112
113# this should show our new virtual device:
114#
115system("cat /proc/bus/input/devices 1>&2");
116print STDERR "\n";
117
118#################################################
119# put in your various test injection events here:
120
121#do_key($KEY_A, 1, 0.1);
122#do_key($KEY_A, 0, 0.1);
123
124#do_key($KEY_POWER, 1, 0.1);
125#do_key($KEY_POWER, 0, 0.1);
126
127do_abs(118, 452, 0, 0.1);
128
129do_abs(110, 572, 1, 0.1);
130
131do_btn($BTN_TOUCH, 1, 0.1);
132do_btn($BTN_TOUCH, 0, 0.1);
133
134do_btn($BTN_MOUSE, 1, 0.1);
135do_btn($BTN_MOUSE, 0, 0.1);
136#################################################
137
138fsleep(0.25);
139io_ctl($UI_DEV_DESTROY);
140
141close(FD);
142
143exit(0);
144
145sub io_ctl {
146	my ($cmd, $val) = @_;
147	if (defined $val) {
148		my $ret = syscall($linux_ioctl_syscall, fileno(FD), $cmd, $val);
149		my $err = $!; $err = '' if $ret == 0;
150		print STDERR "io_ctl(FD, $cmd, $val) = $ret  $err\n";
151	} else {
152		my $ret = syscall($linux_ioctl_syscall, fileno(FD), $cmd);
153		my $err = $!; $err = '' if $ret == 0;
154		print STDERR "io_ctl(FD, $cmd) = $ret  $err\n";
155	}
156}
157
158sub do_syn {
159	my $ev = gtod();
160	$ev .= pack("S", $EV_SYN);
161	$ev .= pack("S", $SYN_REPORT);
162	$ev .= pack("i", 0);
163	print STDERR "do_syn EV_SYN\n";
164	my $ret = syswrite(FD, $ev, length($ev));
165	if (!defined $ret) {
166		print STDERR "do_syn: $!\n";
167	}
168}
169
170sub do_key {
171	my ($key, $down, $sleep) = @_;
172	my $ev = gtod();
173	$ev .= pack("S", $EV_KEY);
174	$ev .= pack("S", $key);
175	$ev .= pack("i", $down);
176	print STDERR "do_key $key $down\n";
177	my $ret = syswrite(FD, $ev, length($ev));
178	if (!defined $ret) {
179		print STDERR "do_key: $!\n";
180	}
181	do_syn();
182	fsleep($sleep);
183	print STDERR "\n";
184}
185
186sub do_btn {
187	my ($button, $down, $sleep) = @_;
188	my $ev = gtod();
189	$ev .= pack("S", $EV_KEY);
190	$ev .= pack("S", $button);
191	$ev .= pack("i", $down);
192	print STDERR "do_btn $button $down\n";
193	my $ret = syswrite(FD, $ev, length($ev));
194	if (!defined $ret) {
195		print STDERR "do_btn: $!\n";
196	}
197	do_syn();
198	fsleep($sleep);
199	print STDERR "\n";
200}
201
202sub do_abs {
203	my ($x, $y, $p, $sleep) = @_;
204	my $ev = gtod();
205	$ev .= pack("S", $EV_ABS);
206	$ev .= pack("S", $ABS_Y);
207	$ev .= pack("i", $y);
208	print STDERR "do_abs y=$y\n";
209	my $ret = syswrite(FD, $ev, length($ev));
210	if (!defined $ret) {
211		print STDERR "do_abs: $!\n";
212	}
213	$ev = gtod();
214	$ev .= pack("S", $EV_ABS);
215	$ev .= pack("S", $ABS_X);
216	$ev .= pack("i", $x);
217	print STDERR "do_abs x=$x\n";
218	$ret = syswrite(FD, $ev, length($ev));
219	if (!defined $ret) {
220		print STDERR "do_abs: $!\n";
221	}
222	$ev = gtod();
223	$ev .= pack("S", $EV_ABS);
224	$ev .= pack("S", $ABS_PRESSURE);
225	$ev .= pack("i", $p);
226	print STDERR "do_abs p=$p\n";
227	$ret = syswrite(FD, $ev, length($ev));
228	if (!defined $ret) {
229		print STDERR "do_abs: $!\n";
230	}
231	do_syn();
232	fsleep($sleep);
233	print STDERR "\n";
234}
235
236sub do_rel {
237	my ($dx, $dy, $sleep) = @_;
238	my $ev = gtod();
239	$ev .= pack("S", $EV_REL);
240	$ev .= pack("S", $REL_Y);
241	$ev .= pack("i", $dy);
242	print STDERR "do_rel dy=$dy\n";
243	my $ret = syswrite(FD, $ev, length($ev));
244	if (!defined $ret) {
245		print STDERR "do_rel: $!\n";
246	}
247	$ev = gtod();
248	$ev .= pack("S", $EV_REL);
249	$ev .= pack("S", $REL_X);
250	$ev .= pack("i", $dx);
251	print STDERR "do_rel dx=$dx\n";
252	$ret = syswrite(FD, $ev, length($ev));
253	if (!defined $ret) {
254		print STDERR "do_rel: $!\n";
255	}
256	do_syn();
257	fsleep($sleep);
258	print STDERR "\n";
259}
260
261sub gtod {
262	$tv = ("\0" x 4) x 2;   # assumes long is 4 bytes.  FIXME: use pack.
263	$tz = ("\0" x 4) x 2;
264	syscall($linux_gettimeofday_syscall, $tv, $tz);
265	return $tv;
266}
267
268sub fsleep {
269        my ($time) = @_;
270        select(undef, undef, undef, $time) if $time;
271}
272
273sub set_constants {
274
275# from /usr/include/linux/uinput.h /usr/include/linux/input.h and x11vnc.
276
277# #define ABS_MAX                 0x3f = 63
278#
279# #define UINPUT_MAX_NAME_SIZE    80
280#
281# struct input_id {
282#         __u16 bustype;
283#         __u16 vendor;
284#         __u16 product;
285#         __u16 version;
286# };
287#
288# struct uinput_user_dev {
289#         char name[UINPUT_MAX_NAME_SIZE];
290#         struct input_id id;
291#         int ff_effects_max;
292#         int absmax[ABS_MAX + 1];
293#         int absmin[ABS_MAX + 1];
294#         int absfuzz[ABS_MAX + 1];
295#         int absflat[ABS_MAX + 1];
296# };
297# #endif  /* __UINPUT_H_ */
298
299$EV_SYN                  = 0x00;
300$EV_KEY                  = 0x01;
301$EV_REL                  = 0x02;
302$EV_ABS                  = 0x03;
303$EV_MSC                  = 0x04;
304$EV_SW                   = 0x05;
305$EV_LED                  = 0x11;
306$EV_SND                  = 0x12;
307$EV_REP                  = 0x14;
308$EV_FF                   = 0x15;
309$EV_PWR                  = 0x16;
310$EV_FF_STATUS            = 0x17;
311$EV_MAX                  = 0x1f;
312
313$ID_BUS                  = 0;
314$ID_VENDOR               = 1;
315$ID_PRODUCT              = 2;
316$ID_VERSION              = 3;
317
318$BUS_PCI                 = 0x01;
319$BUS_ISAPNP              = 0x02;
320$BUS_USB                 = 0x03;
321$BUS_HIL                 = 0x04;
322$BUS_BLUETOOTH           = 0x05;
323$BUS_VIRTUAL             = 0x06;
324
325$BUS_ISA                 = 0x10;
326$BUS_I8042               = 0x11;
327$BUS_XTKBD               = 0x12;
328$BUS_RS232               = 0x13;
329$BUS_GAMEPORT            = 0x14;
330$BUS_PARPORT             = 0x15;
331$BUS_AMIGA               = 0x16;
332$BUS_ADB                 = 0x17;
333$BUS_I2C                 = 0x18;
334$BUS_HOST                = 0x19;
335$BUS_GSC                 = 0x1A;
336$BUS_ATARI               = 0x1B;
337
338$REL_X                   = 0x00;
339$REL_Y                   = 0x01;
340$REL_Z                   = 0x02;
341$REL_RX                  = 0x03;
342$REL_RY                  = 0x04;
343$REL_RZ                  = 0x05;
344$REL_HWHEEL              = 0x06;
345$REL_DIAL                = 0x07;
346$REL_WHEEL               = 0x08;
347$REL_MISC                = 0x09;
348
349$ABS_X                   = 0x00;
350$ABS_Y                   = 0x01;
351$ABS_Z                   = 0x02;
352$ABS_RX                  = 0x03;
353$ABS_RY                  = 0x04;
354$ABS_RZ                  = 0x05;
355$ABS_THROTTLE            = 0x06;
356$ABS_RUDDER              = 0x07;
357$ABS_WHEEL               = 0x08;
358$ABS_GAS                 = 0x09;
359$ABS_BRAKE               = 0x0a;
360$ABS_HAT0X               = 0x10;
361$ABS_HAT0Y               = 0x11;
362$ABS_HAT1X               = 0x12;
363$ABS_HAT1Y               = 0x13;
364$ABS_HAT2X               = 0x14;
365$ABS_HAT2Y               = 0x15;
366$ABS_HAT3X               = 0x16;
367$ABS_HAT3Y               = 0x17;
368$ABS_PRESSURE            = 0x18;
369$ABS_DISTANCE            = 0x19;
370$ABS_TILT_X              = 0x1a;
371$ABS_TILT_Y              = 0x1b;
372$ABS_TOOL_WIDTH          = 0x1c;
373$ABS_VOLUME              = 0x20;
374$ABS_MISC                = 0x28;
375$ABS_MT_TOUCH_MAJOR      = 0x30;
376$ABS_MT_TOUCH_MINOR      = 0x31;
377$ABS_MT_WIDTH_MAJOR      = 0x32;
378$ABS_MT_WIDTH_MINOR      = 0x33;
379$ABS_MT_ORIENTATION      = 0x34;
380$ABS_MT_POSITION_X       = 0x35;
381$ABS_MT_POSITION_Y       = 0x36;
382$ABS_MT_TOOL_TYPE        = 0x37;
383$ABS_MT_BLOB_ID          = 0x38;
384$ABS_MT_TRACKING_ID      = 0x39;
385#$ABS_MAX = 0x3f;
386
387
388$BTN_MISC                = 0x100;
389$BTN_0                   = 0x100;
390$BTN_1                   = 0x101;
391$BTN_2                   = 0x102;
392$BTN_3                   = 0x103;
393$BTN_4                   = 0x104;
394$BTN_5                   = 0x105;
395$BTN_6                   = 0x106;
396$BTN_7                   = 0x107;
397$BTN_8                   = 0x108;
398$BTN_9                   = 0x109;
399
400$BTN_MOUSE               = 0x110;
401$BTN_LEFT                = 0x110;
402$BTN_RIGHT               = 0x111;
403$BTN_MIDDLE              = 0x112;
404$BTN_SIDE                = 0x113;
405$BTN_EXTRA               = 0x114;
406$BTN_FORWARD             = 0x115;
407$BTN_BACK                = 0x116;
408$BTN_TASK                = 0x117;
409
410$BTN_JOYSTICK            = 0x120;
411$BTN_TRIGGER             = 0x120;
412$BTN_THUMB               = 0x121;
413$BTN_THUMB2              = 0x122;
414$BTN_TOP                 = 0x123;
415$BTN_TOP2                = 0x124;
416$BTN_PINKIE              = 0x125;
417$BTN_BASE                = 0x126;
418$BTN_BASE2               = 0x127;
419$BTN_BASE3               = 0x128;
420$BTN_BASE4               = 0x129;
421$BTN_BASE5               = 0x12a;
422$BTN_BASE6               = 0x12b;
423$BTN_DEAD                = 0x12f;
424
425$BTN_GAMEPAD             = 0x130;
426$BTN_A                   = 0x130;
427$BTN_B                   = 0x131;
428$BTN_C                   = 0x132;
429$BTN_X                   = 0x133;
430$BTN_Y                   = 0x134;
431$BTN_Z                   = 0x135;
432$BTN_TL                  = 0x136;
433$BTN_TR                  = 0x137;
434$BTN_TL2                 = 0x138;
435$BTN_TR2                 = 0x139;
436$BTN_SELECT              = 0x13a;
437$BTN_START               = 0x13b;
438$BTN_MODE                = 0x13c;
439$BTN_THUMBL              = 0x13d;
440$BTN_THUMBR              = 0x13e;
441
442$BTN_DIGI                = 0x140;
443$BTN_TOOL_PEN            = 0x140;
444$BTN_TOOL_RUBBER         = 0x141;
445$BTN_TOOL_BRUSH          = 0x142;
446$BTN_TOOL_PENCIL         = 0x143;
447$BTN_TOOL_AIRBRUSH       = 0x144;
448$BTN_TOOL_FINGER         = 0x145;
449$BTN_TOOL_MOUSE          = 0x146;
450$BTN_TOOL_LENS           = 0x147;
451$BTN_TOUCH               = 0x14a;
452$BTN_STYLUS              = 0x14b;
453$BTN_STYLUS2             = 0x14c;
454$BTN_TOOL_DOUBLETAP      = 0x14d;
455$BTN_TOOL_TRIPLETAP      = 0x14e;
456
457$BTN_WHEEL               = 0x150;
458$BTN_GEAR_DOWN           = 0x150;
459$BTN_GEAR_UP             = 0x151;
460
461$SYN_REPORT              = 0;
462$SYN_CONFIG              = 1;
463$SYN_MT_REPORT           = 2;
464
465$KEY_RESERVED = 0;
466$KEY_ESC =      1;
467$KEY_1 =        2;
468$KEY_2 =        3;
469$KEY_3 =        4;
470$KEY_4 =        5;
471$KEY_5 =        6;
472$KEY_6 =        7;
473$KEY_7 =        8;
474$KEY_8 =        9;
475$KEY_9 =        10;
476$KEY_0 =        11;
477$KEY_MINUS =    12;
478$KEY_EQUAL =    13;
479$KEY_BACKSPACE =        14;
480$KEY_TAB =      15;
481$KEY_Q =        16;
482$KEY_W =        17;
483$KEY_E =        18;
484$KEY_R =        19;
485$KEY_T =        20;
486$KEY_Y =        21;
487$KEY_U =        22;
488$KEY_I =        23;
489$KEY_O =        24;
490$KEY_P =        25;
491$KEY_LEFTBRACE =        26;
492$KEY_RIGHTBRACE =       27;
493$KEY_ENTER =    28;
494$KEY_LEFTCTRL = 29;
495$KEY_A =        30;
496$KEY_S =        31;
497$KEY_D =        32;
498$KEY_F =        33;
499$KEY_G =        34;
500$KEY_H =        35;
501$KEY_J =        36;
502$KEY_K =        37;
503$KEY_L =        38;
504$KEY_SEMICOLON =        39;
505$KEY_APOSTROPHE =       40;
506$KEY_GRAVE =    41;
507$KEY_LEFTSHIFT =        42;
508$KEY_BACKSLASH =        43;
509$KEY_Z =        44;
510$KEY_X =        45;
511$KEY_C =        46;
512$KEY_V =        47;
513$KEY_B =        48;
514$KEY_N =        49;
515$KEY_M =        50;
516$KEY_COMMA =    51;
517$KEY_DOT =      52;
518$KEY_SLASH =    53;
519$KEY_RIGHTSHIFT =       54;
520$KEY_KPASTERISK =       55;
521$KEY_LEFTALT =  56;
522$KEY_SPACE =    57;
523$KEY_CAPSLOCK = 58;
524$KEY_F1 =       59;
525$KEY_F2 =       60;
526$KEY_F3 =       61;
527$KEY_F4 =       62;
528$KEY_F5 =       63;
529$KEY_F6 =       64;
530$KEY_F7 =       65;
531$KEY_F8 =       66;
532$KEY_F9 =       67;
533$KEY_F10 =      68;
534$KEY_NUMLOCK =  69;
535$KEY_SCROLLLOCK =       70;
536$KEY_KP7 =      71;
537$KEY_KP8 =      72;
538$KEY_KP9 =      73;
539$KEY_KPMINUS =  74;
540$KEY_KP4 =      75;
541$KEY_KP5 =      76;
542$KEY_KP6 =      77;
543$KEY_KPPLUS =   78;
544$KEY_KP1 =      79;
545$KEY_KP2 =      80;
546$KEY_KP3 =      81;
547$KEY_KP0 =      82;
548$KEY_KPDOT =    83;
549$KEY_103RD =    84;
550$KEY_F13 =      85;
551$KEY_102ND =    86;
552$KEY_F11 =      87;
553$KEY_F12 =      88;
554$KEY_F14 =      89;
555$KEY_F15 =      90;
556$KEY_F16 =      91;
557$KEY_F17 =      92;
558$KEY_F18 =      93;
559$KEY_F19 =      94;
560$KEY_F20 =      95;
561$KEY_KPENTER =  96;
562$KEY_RIGHTCTRL =        97;
563$KEY_KPSLASH =  98;
564$KEY_SYSRQ =    99;
565$KEY_RIGHTALT = 100;
566$KEY_LINEFEED = 101;
567$KEY_HOME =     102;
568$KEY_UP =       103;
569$KEY_PAGEUP =   104;
570$KEY_LEFT =     105;
571$KEY_RIGHT =    106;
572$KEY_END =      107;
573$KEY_DOWN =     108;
574$KEY_PAGEDOWN = 109;
575$KEY_INSERT =   110;
576$KEY_DELETE =   111;
577$KEY_MACRO =    112;
578$KEY_MUTE =     113;
579$KEY_VOLUMEDOWN =       114;
580$KEY_VOLUMEUP = 115;
581$KEY_POWER =    116;
582$KEY_KPEQUAL =  117;
583$KEY_KPPLUSMINUS =      118;
584$KEY_PAUSE =    119;
585$KEY_F21 =      120;
586$KEY_F22 =      121;
587$KEY_F23 =      122;
588$KEY_F24 =      123;
589$KEY_KPCOMMA =  124;
590$KEY_LEFTMETA = 125;
591$KEY_RIGHTMETA =        126;
592$KEY_COMPOSE =  127;
593$KEY_STOP =     128;
594$KEY_AGAIN =    129;
595$KEY_PROPS =    130;
596$KEY_UNDO =     131;
597$KEY_FRONT =    132;
598$KEY_COPY =     133;
599$KEY_OPEN =     134;
600$KEY_PASTE =    135;
601$KEY_FIND =     136;
602$KEY_CUT =      137;
603$KEY_HELP =     138;
604$KEY_MENU =     139;
605$KEY_CALC =     140;
606$KEY_SETUP =    141;
607$KEY_SLEEP =    142;
608$KEY_WAKEUP =   143;
609$KEY_FILE =     144;
610$KEY_SENDFILE = 145;
611$KEY_DELETEFILE =       146;
612$KEY_XFER =     147;
613$KEY_PROG1 =    148;
614$KEY_PROG2 =    149;
615$KEY_WWW =      150;
616$KEY_MSDOS =    151;
617$KEY_COFFEE =   152;
618$KEY_DIRECTION =        153;
619$KEY_CYCLEWINDOWS =     154;
620$KEY_MAIL =     155;
621$KEY_BOOKMARKS =        156;
622$KEY_COMPUTER = 157;
623$KEY_BACK =     158;
624$KEY_FORWARD =  159;
625$KEY_CLOSECD =  160;
626$KEY_EJECTCD =  161;
627$KEY_EJECTCLOSECD =     162;
628$KEY_NEXTSONG = 163;
629$KEY_PLAYPAUSE =        164;
630$KEY_PREVIOUSSONG =     165;
631$KEY_STOPCD =   166;
632$KEY_RECORD =   167;
633$KEY_REWIND =   168;
634$KEY_PHONE =    169;
635$KEY_ISO =      170;
636$KEY_CONFIG =   171;
637$KEY_HOMEPAGE = 172;
638$KEY_REFRESH =  173;
639$KEY_EXIT =     174;
640$KEY_MOVE =     175;
641$KEY_EDIT =     176;
642$KEY_SCROLLUP = 177;
643$KEY_SCROLLDOWN =       178;
644$KEY_KPLEFTPAREN =      179;
645$KEY_KPRIGHTPAREN =     180;
646$KEY_INTL1 =    181;
647$KEY_INTL2 =    182;
648$KEY_INTL3 =    183;
649$KEY_INTL4 =    184;
650$KEY_INTL5 =    185;
651$KEY_INTL6 =    186;
652$KEY_INTL7 =    187;
653$KEY_INTL8 =    188;
654$KEY_INTL9 =    189;
655$KEY_LANG1 =    190;
656$KEY_LANG2 =    191;
657$KEY_LANG3 =    192;
658$KEY_LANG4 =    193;
659$KEY_LANG5 =    194;
660$KEY_LANG6 =    195;
661$KEY_LANG7 =    196;
662$KEY_LANG8 =    197;
663$KEY_LANG9 =    198;
664$KEY_PLAYCD =   200;
665$KEY_PAUSECD =  201;
666$KEY_PROG3 =    202;
667$KEY_PROG4 =    203;
668$KEY_SUSPEND =  205;
669$KEY_CLOSE =    206;
670$KEY_PLAY =     207;
671$KEY_FASTFORWARD =      208;
672$KEY_BASSBOOST =        209;
673$KEY_PRINT =    210;
674$KEY_HP =       211;
675$KEY_CAMERA =   212;
676$KEY_SOUND =    213;
677$KEY_QUESTION = 214;
678$KEY_EMAIL =    215;
679$KEY_CHAT =     216;
680$KEY_SEARCH =   217;
681$KEY_CONNECT =  218;
682$KEY_FINANCE =  219;
683$KEY_SPORT =    220;
684$KEY_SHOP =     221;
685$KEY_ALTERASE = 222;
686$KEY_CANCEL =   223;
687$KEY_BRIGHTNESSDOWN =   224;
688$KEY_BRIGHTNESSUP =     225;
689$KEY_MEDIA =    226;
690$KEY_UNKNOWN =  240;
691$KEY_OK =       0x160;
692$KEY_SELECT =   0x161;
693$KEY_GOTO =     0x162;
694$KEY_CLEAR =    0x163;
695$KEY_POWER2 =   0x164;
696$KEY_OPTION =   0x165;
697$KEY_INFO =     0x166;
698$KEY_TIME =     0x167;
699$KEY_VENDOR =   0x168;
700$KEY_ARCHIVE =  0x169;
701$KEY_PROGRAM =  0x16a;
702$KEY_CHANNEL =  0x16b;
703$KEY_FAVORITES =        0x16c;
704$KEY_EPG =      0x16d;
705$KEY_PVR =      0x16e;
706$KEY_MHP =      0x16f;
707$KEY_LANGUAGE = 0x170;
708$KEY_TITLE =    0x171;
709$KEY_SUBTITLE = 0x172;
710$KEY_ANGLE =    0x173;
711$KEY_ZOOM =     0x174;
712$KEY_MODE =     0x175;
713$KEY_KEYBOARD = 0x176;
714$KEY_SCREEN =   0x177;
715$KEY_PC =       0x178;
716$KEY_TV =       0x179;
717$KEY_TV2 =      0x17a;
718$KEY_VCR =      0x17b;
719$KEY_VCR2 =     0x17c;
720$KEY_SAT =      0x17d;
721$KEY_SAT2 =     0x17e;
722$KEY_CD =       0x17f;
723$KEY_TAPE =     0x180;
724$KEY_RADIO =    0x181;
725$KEY_TUNER =    0x182;
726$KEY_PLAYER =   0x183;
727$KEY_TEXT =     0x184;
728$KEY_DVD =      0x185;
729$KEY_AUX =      0x186;
730$KEY_MP3 =      0x187;
731$KEY_AUDIO =    0x188;
732$KEY_VIDEO =    0x189;
733$KEY_DIRECTORY =        0x18a;
734$KEY_LIST =     0x18b;
735$KEY_MEMO =     0x18c;
736$KEY_CALENDAR = 0x18d;
737$KEY_RED =      0x18e;
738$KEY_GREEN =    0x18f;
739$KEY_YELLOW =   0x190;
740$KEY_BLUE =     0x191;
741$KEY_CHANNELUP =        0x192;
742$KEY_CHANNELDOWN =      0x193;
743$KEY_FIRST =    0x194;
744$KEY_LAST =     0x195;
745$KEY_AB =       0x196;
746$KEY_NEXT =     0x197;
747$KEY_RESTART =  0x198;
748$KEY_SLOW =     0x199;
749$KEY_SHUFFLE =  0x19a;
750$KEY_BREAK =    0x19b;
751$KEY_PREVIOUS = 0x19c;
752$KEY_DIGITS =   0x19d;
753$KEY_TEEN =     0x19e;
754$KEY_TWEN =     0x19f;
755$KEY_DEL_EOL =  0x1c0;
756$KEY_DEL_EOS =  0x1c1;
757$KEY_INS_LINE = 0x1c2;
758$KEY_DEL_LINE = 0x1c3;
759$KEY_MAX =      0x1ff;
760
761
762        $key_lookup{XK_Escape}  = $KEY_ESC;
763        $key_lookup{XK_1}               = $KEY_1;
764        $key_lookup{XK_2}               = $KEY_2;
765        $key_lookup{XK_3}               = $KEY_3;
766        $key_lookup{XK_4}               = $KEY_4;
767        $key_lookup{XK_5}               = $KEY_5;
768        $key_lookup{XK_6}               = $KEY_6;
769        $key_lookup{XK_7}               = $KEY_7;
770        $key_lookup{XK_8}               = $KEY_8;
771        $key_lookup{XK_9}               = $KEY_9;
772        $key_lookup{XK_0}               = $KEY_0;
773        $key_lookup{XK_exclam}  = $KEY_1;
774        $key_lookup{XK_at}              = $KEY_2;
775        $key_lookup{XK_numbersign}      = $KEY_3;
776        $key_lookup{XK_dollar}  = $KEY_4;
777        $key_lookup{XK_percent} = $KEY_5;
778        $key_lookup{XK_asciicircum}     = $KEY_6;
779        $key_lookup{XK_ampersand}       = $KEY_7;
780        $key_lookup{XK_asterisk}        = $KEY_8;
781        $key_lookup{XK_parenleft}       = $KEY_9;
782        $key_lookup{XK_parenright}      = $KEY_0;
783        $key_lookup{XK_minus}   = $KEY_MINUS;
784        $key_lookup{XK_underscore}      = $KEY_MINUS;
785        $key_lookup{XK_equal}   = $KEY_EQUAL;
786        $key_lookup{XK_plus}    = $KEY_EQUAL;
787        $key_lookup{XK_BackSpace}       = $KEY_BACKSPACE;
788        $key_lookup{XK_Tab}             = $KEY_TAB;
789        $key_lookup{XK_q}               = $KEY_Q;
790        $key_lookup{XK_Q}               = $KEY_Q;
791        $key_lookup{XK_w}               = $KEY_W;
792        $key_lookup{XK_W}               = $KEY_W;
793        $key_lookup{XK_e}               = $KEY_E;
794        $key_lookup{XK_E}               = $KEY_E;
795        $key_lookup{XK_r}               = $KEY_R;
796        $key_lookup{XK_R}               = $KEY_R;
797        $key_lookup{XK_t}               = $KEY_T;
798        $key_lookup{XK_T}               = $KEY_T;
799        $key_lookup{XK_y}               = $KEY_Y;
800        $key_lookup{XK_Y}               = $KEY_Y;
801        $key_lookup{XK_u}               = $KEY_U;
802        $key_lookup{XK_U}               = $KEY_U;
803        $key_lookup{XK_i}               = $KEY_I;
804        $key_lookup{XK_I}               = $KEY_I;
805        $key_lookup{XK_o}               = $KEY_O;
806        $key_lookup{XK_O}               = $KEY_O;
807        $key_lookup{XK_p}               = $KEY_P;
808        $key_lookup{XK_P}               = $KEY_P;
809        $key_lookup{XK_braceleft}       = $KEY_LEFTBRACE;
810        $key_lookup{XK_braceright}      = $KEY_RIGHTBRACE;
811        $key_lookup{XK_bracketleft}     = $KEY_LEFTBRACE;
812        $key_lookup{XK_bracketright}    = $KEY_RIGHTBRACE;
813        $key_lookup{XK_Return}  = $KEY_ENTER;
814        $key_lookup{XK_Control_L}       = $KEY_LEFTCTRL;
815        $key_lookup{XK_a}               = $KEY_A;
816        $key_lookup{XK_A}               = $KEY_A;
817        $key_lookup{XK_s}               = $KEY_S;
818        $key_lookup{XK_S}               = $KEY_S;
819        $key_lookup{XK_d}               = $KEY_D;
820        $key_lookup{XK_D}               = $KEY_D;
821        $key_lookup{XK_f}               = $KEY_F;
822        $key_lookup{XK_F}               = $KEY_F;
823        $key_lookup{XK_g}               = $KEY_G;
824        $key_lookup{XK_G}               = $KEY_G;
825        $key_lookup{XK_h}               = $KEY_H;
826        $key_lookup{XK_H}               = $KEY_H;
827        $key_lookup{XK_j}               = $KEY_J;
828        $key_lookup{XK_J}               = $KEY_J;
829        $key_lookup{XK_k}               = $KEY_K;
830        $key_lookup{XK_K}               = $KEY_K;
831        $key_lookup{XK_l}               = $KEY_L;
832        $key_lookup{XK_L}               = $KEY_L;
833        $key_lookup{XK_semicolon}       = $KEY_SEMICOLON;
834        $key_lookup{XK_colon}   = $KEY_SEMICOLON;
835        $key_lookup{XK_apostrophe}      = $KEY_APOSTROPHE;
836        $key_lookup{XK_quotedbl}        = $KEY_APOSTROPHE;
837        $key_lookup{XK_grave}   = $KEY_GRAVE;
838        $key_lookup{XK_asciitilde}      = $KEY_GRAVE;
839        $key_lookup{XK_Shift_L} = $KEY_LEFTSHIFT;
840        $key_lookup{XK_backslash}       = $KEY_BACKSLASH;
841        $key_lookup{XK_bar}             = $KEY_BACKSLASH;
842        $key_lookup{XK_z}               = $KEY_Z;
843        $key_lookup{XK_Z}               = $KEY_Z;
844        $key_lookup{XK_x}               = $KEY_X;
845        $key_lookup{XK_X}               = $KEY_X;
846        $key_lookup{XK_c}               = $KEY_C;
847        $key_lookup{XK_C}               = $KEY_C;
848        $key_lookup{XK_v}               = $KEY_V;
849        $key_lookup{XK_V}               = $KEY_V;
850        $key_lookup{XK_b}               = $KEY_B;
851        $key_lookup{XK_B}               = $KEY_B;
852        $key_lookup{XK_n}               = $KEY_N;
853        $key_lookup{XK_N}               = $KEY_N;
854        $key_lookup{XK_m}               = $KEY_M;
855        $key_lookup{XK_M}               = $KEY_M;
856        $key_lookup{XK_comma}   = $KEY_COMMA;
857        $key_lookup{XK_less}    = $KEY_COMMA;
858        $key_lookup{XK_period}  = $KEY_DOT;
859        $key_lookup{XK_greater} = $KEY_DOT;
860        $key_lookup{XK_slash}   = $KEY_SLASH;
861        $key_lookup{XK_question}        = $KEY_SLASH;
862        $key_lookup{XK_Shift_R} = $KEY_RIGHTSHIFT;
863        $key_lookup{XK_KP_Multiply}     = $KEY_KPASTERISK;
864        $key_lookup{XK_Alt_L}   = $KEY_LEFTALT;
865        $key_lookup{XK_space}   = $KEY_SPACE;
866        $key_lookup{XK_Caps_Lock}       = $KEY_CAPSLOCK;
867        $key_lookup{XK_F1}              = $KEY_F1;
868        $key_lookup{XK_F2}              = $KEY_F2;
869        $key_lookup{XK_F3}              = $KEY_F3;
870        $key_lookup{XK_F4}              = $KEY_F4;
871        $key_lookup{XK_F5}              = $KEY_F5;
872        $key_lookup{XK_F6}              = $KEY_F6;
873        $key_lookup{XK_F7}              = $KEY_F7;
874        $key_lookup{XK_F8}              = $KEY_F8;
875        $key_lookup{XK_F9}              = $KEY_F9;
876        $key_lookup{XK_F10}             = $KEY_F10;
877        $key_lookup{XK_Num_Lock}        = $KEY_NUMLOCK;
878        $key_lookup{XK_Scroll_Lock}     = $KEY_SCROLLLOCK;
879        $key_lookup{XK_KP_7}            = $KEY_KP7;
880        $key_lookup{XK_KP_8}            = $KEY_KP8;
881        $key_lookup{XK_KP_9}            = $KEY_KP9;
882        $key_lookup{XK_KP_Subtract}     = $KEY_KPMINUS;
883        $key_lookup{XK_KP_4}            = $KEY_KP4;
884        $key_lookup{XK_KP_5}            = $KEY_KP5;
885        $key_lookup{XK_KP_6}            = $KEY_KP6;
886        $key_lookup{XK_KP_Add}  = $KEY_KPPLUS;
887        $key_lookup{XK_KP_1}            = $KEY_KP1;
888        $key_lookup{XK_KP_2}            = $KEY_KP2;
889        $key_lookup{XK_KP_3}            = $KEY_KP3;
890        $key_lookup{XK_KP_0}            = $KEY_KP0;
891        $key_lookup{XK_KP_Decimal}      = $KEY_KPDOT;
892        $key_lookup{XK_F13}             = $KEY_F13;
893        $key_lookup{XK_F11}             = $KEY_F11;
894        $key_lookup{XK_F12}             = $KEY_F12;
895        $key_lookup{XK_F14}             = $KEY_F14;
896        $key_lookup{XK_F15}             = $KEY_F15;
897        $key_lookup{XK_F16}             = $KEY_F16;
898        $key_lookup{XK_F17}             = $KEY_F17;
899        $key_lookup{XK_F18}             = $KEY_F18;
900        $key_lookup{XK_F19}             = $KEY_F19;
901        $key_lookup{XK_F20}             = $KEY_F20;
902        $key_lookup{XK_KP_Enter}        = $KEY_KPENTER;
903        $key_lookup{XK_Control_R}       = $KEY_RIGHTCTRL;
904        $key_lookup{XK_KP_Divide}       = $KEY_KPSLASH;
905        $key_lookup{XK_Sys_Req} = $KEY_SYSRQ;
906        $key_lookup{XK_Alt_R}   = $KEY_RIGHTALT;
907        $key_lookup{XK_Linefeed}        = $KEY_LINEFEED;
908        $key_lookup{XK_Home}            = $KEY_HOME;
909        $key_lookup{XK_Up}              = $KEY_UP;
910        $key_lookup{XK_Page_Up} = $KEY_PAGEUP;
911        $key_lookup{XK_Left}            = $KEY_LEFT;
912        $key_lookup{XK_Right}   = $KEY_RIGHT;
913        $key_lookup{XK_End}             = $KEY_END;
914        $key_lookup{XK_Down}            = $KEY_DOWN;
915        $key_lookup{XK_Page_Down}       = $KEY_PAGEDOWN;
916        $key_lookup{XK_Insert}  = $KEY_INSERT;
917        $key_lookup{XK_Delete}  = $KEY_DELETE;
918        $key_lookup{XK_KP_Equal}        = $KEY_KPEQUAL;
919        $key_lookup{XK_Pause}   = $KEY_PAUSE;
920        $key_lookup{XK_F21}             = $KEY_F21;
921        $key_lookup{XK_F22}             = $KEY_F22;
922        $key_lookup{XK_F23}             = $KEY_F23;
923        $key_lookup{XK_F24}             = $KEY_F24;
924        $key_lookup{XK_KP_Separator}    = $KEY_KPCOMMA;
925        $key_lookup{XK_Meta_L}  = $KEY_LEFTMETA;
926        $key_lookup{XK_Meta_R}  = $KEY_RIGHTMETA;
927        $key_lookup{XK_Multi_key}       = $KEY_COMPOSE;
928
929$ABS_MAX = 63;
930
931$UI_DEV_CREATE  = 0x5501;
932$UI_DEV_DESTROY = 0x5502;
933$UI_SET_EVBIT   = 0x40045564;
934$UI_SET_KEYBIT  = 0x40045565;
935$UI_SET_RELBIT  = 0x40045566;
936$UI_SET_ABSBIT  = 0x40045567;
937
938# FIXME: time hires, etc.
939$linux_gettimeofday_syscall = 78;
940
941$O_RDONLY = 00;
942$O_WRONLY = 01;
943$O_RDWR   = 02;
944$O_NDELAY = 04000;
945
946}
947