Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

input.h

Go to the documentation of this file.
00001 #ifndef _INPUT_H
00002 #define _INPUT_H
00003 
00004 /*
00005  * $Id: input.h,v 1.13 2000/05/29 10:54:53 vojtech Exp $
00006  *
00007  *  Copyright (c) 1999-2000 Vojtech Pavlik
00008  *
00009  *  Sponsored by SuSE
00010  */
00011 
00012 /*
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or 
00016  * (at your option) any later version.
00017  * 
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  * 
00027  * Should you need to contact me, the author, you can do so either by
00028  * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
00029  * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
00030  */
00031 
00032 #ifdef __KERNEL__
00033 #include <linux/time.h>
00034 #else
00035 #include <sys/time.h>
00036 #include <sys/ioctl.h>
00037 #endif
00038 
00039 /*
00040  * The event structure itself
00041  */
00042 
00043 struct input_event {
00044         struct timeval time;
00045         unsigned short type;
00046         unsigned short code;
00047         unsigned int value;
00048 };
00049 
00050 /*
00051  * Protocol version.
00052  */
00053 
00054 #define EV_VERSION              0x010000
00055 
00056 /*
00057  * IOCTLs (0x00 - 0x7f)
00058  */
00059 
00060 #define EVIOCGVERSION           _IOR('E', 0x01, int)                    /* get driver version */
00061 #define EVIOCGID                _IOR('E', 0x02, short[4])               /* get device ID */
00062 #define EVIOCGREP               _IOR('E', 0x03, int[2])                 /* get repeat settings */
00063 #define EVIOCSREP               _IOW('E', 0x03, int[2])                 /* get repeat settings */
00064 #define EVIOCGKEYCODE           _IOR('E', 0x04, int[2])                 /* get keycode */
00065 #define EVIOCSKEYCODE           _IOW('E', 0x04, int[2])                 /* set keycode */
00066 #define EVIOCGKEY               _IOR('E', 0x05, int[2])                 /* get key value */
00067 #define EVIOCGNAME(len)         _IOC(_IOC_READ, 'E', 0x06, len)         /* get device name */
00068 
00069 #define EVIOCGBIT(ev,len)       _IOC(_IOC_READ, 'E', 0x20 + ev, len)    /* get event bits */
00070 #define EVIOCGABS(abs)          _IOR('E', 0x40 + abs, int[5])           /* get abs value/limits */ 
00071 
00072 /*
00073  * Event types
00074  */
00075 
00076 #define EV_RST                  0x00
00077 #define EV_KEY                  0x01
00078 #define EV_REL                  0x02
00079 #define EV_ABS                  0x03
00080 #define EV_LED                  0x11
00081 #define EV_SND                  0x12
00082 #define EV_REP                  0x14
00083 #define EV_MAX                  0x1f
00084 
00085 /*
00086  * Keys and buttons
00087  */
00088 
00089 #define KEY_RESERVED            0               
00090 #define KEY_ESC                 1               
00091 #define KEY_1                   2               
00092 #define KEY_2                   3               
00093 #define KEY_3                   4               
00094 #define KEY_4                   5               
00095 #define KEY_5                   6               
00096 #define KEY_6                   7               
00097 #define KEY_7                   8               
00098 #define KEY_8                   9               
00099 #define KEY_9                   10              
00100 #define KEY_0                   11              
00101 #define KEY_MINUS               12              
00102 #define KEY_EQUAL               13              
00103 #define KEY_BACKSPACE           14              
00104 #define KEY_TAB                 15              
00105 #define KEY_Q                   16              
00106 #define KEY_W                   17              
00107 #define KEY_E                   18              
00108 #define KEY_R                   19              
00109 #define KEY_T                   20              
00110 #define KEY_Y                   21              
00111 #define KEY_U                   22              
00112 #define KEY_I                   23              
00113 #define KEY_O                   24              
00114 #define KEY_P                   25              
00115 #define KEY_LEFTBRACE           26              
00116 #define KEY_RIGHTBRACE          27              
00117 #define KEY_ENTER               28              
00118 #define KEY_LEFTCTRL            29              
00119 #define KEY_A                   30              
00120 #define KEY_S                   31              
00121 #define KEY_D                   32              
00122 #define KEY_F                   33              
00123 #define KEY_G                   34              
00124 #define KEY_H                   35              
00125 #define KEY_J                   36              
00126 #define KEY_K                   37              
00127 #define KEY_L                   38              
00128 #define KEY_SEMICOLON           39              
00129 #define KEY_APOSTROPHE          40              
00130 #define KEY_GRAVE               41              
00131 #define KEY_LEFTSHIFT           42              
00132 #define KEY_BACKSLASH           43              
00133 #define KEY_Z                   44              
00134 #define KEY_X                   45              
00135 #define KEY_C                   46              
00136 #define KEY_V                   47              
00137 #define KEY_B                   48              
00138 #define KEY_N                   49              
00139 #define KEY_M                   50              
00140 #define KEY_COMMA               51              
00141 #define KEY_DOT                 52              
00142 #define KEY_SLASH               53              
00143 #define KEY_RIGHTSHIFT          54              
00144 #define KEY_KPASTERISK          55              
00145 #define KEY_LEFTALT             56              
00146 #define KEY_SPACE               57              
00147 #define KEY_CAPSLOCK            58              
00148 #define KEY_F1                  59              
00149 #define KEY_F2                  60              
00150 #define KEY_F3                  61              
00151 #define KEY_F4                  62              
00152 #define KEY_F5                  63              
00153 #define KEY_F6                  64              
00154 #define KEY_F7                  65              
00155 #define KEY_F8                  66              
00156 #define KEY_F9                  67              
00157 #define KEY_F10                 68              
00158 #define KEY_NUMLOCK             69              
00159 #define KEY_SCROLLLOCK          70              
00160 #define KEY_KP7                 71              
00161 #define KEY_KP8                 72              
00162 #define KEY_KP9                 73              
00163 #define KEY_KPMINUS             74              
00164 #define KEY_KP4                 75              
00165 #define KEY_KP5                 76              
00166 #define KEY_KP6                 77              
00167 #define KEY_KPPLUS              78              
00168 #define KEY_KP1                 79              
00169 #define KEY_KP2                 80              
00170 #define KEY_KP3                 81              
00171 #define KEY_KP0                 82              
00172 #define KEY_KPDOT               83              
00173 #define KEY_103RD               84
00174 #define KEY_F13                 85              
00175 #define KEY_102ND               86              
00176 #define KEY_F11                 87              
00177 #define KEY_F12                 88              
00178 #define KEY_F14                 89              
00179 #define KEY_F15                 90              
00180 #define KEY_F16                 91              
00181 #define KEY_F17                 92              
00182 #define KEY_F18                 93              
00183 #define KEY_F19                 94              
00184 #define KEY_F20                 95              
00185 #define KEY_KPENTER             96              
00186 #define KEY_RIGHTCTRL           97              
00187 #define KEY_KPSLASH             98              
00188 #define KEY_SYSRQ               99              
00189 #define KEY_RIGHTALT            100             
00190 #define KEY_LINEFEED            101             
00191 #define KEY_HOME                102             
00192 #define KEY_UP                  103             
00193 #define KEY_PAGEUP              104             
00194 #define KEY_LEFT                105             
00195 #define KEY_RIGHT               106             
00196 #define KEY_END                 107             
00197 #define KEY_DOWN                108             
00198 #define KEY_PAGEDOWN            109             
00199 #define KEY_INSERT              110             
00200 #define KEY_DELETE              111             
00201 #define KEY_MACRO               112             
00202 #define KEY_MUTE                113             
00203 #define KEY_VOLUMEDOWN          114             
00204 #define KEY_VOLUMEUP            115             
00205 #define KEY_POWER               116             
00206 #define KEY_KPEQUAL             117             
00207 #define KEY_KPPLUSMINUS         118             
00208 #define KEY_PAUSE               119             
00209 #define KEY_F21                 120             
00210 #define KEY_F22                 121             
00211 #define KEY_F23                 122             
00212 #define KEY_F24                 123             
00213 #define KEY_KPCOMMA             124
00214 #define KEY_LEFTMETA            125             
00215 #define KEY_RIGHTMETA           126             
00216 #define KEY_COMPOSE             127             
00217 
00218 #define KEY_STOP                128             
00219 #define KEY_AGAIN               129             
00220 #define KEY_PROPS               130             
00221 #define KEY_UNDO                131             
00222 #define KEY_FRONT               132             
00223 #define KEY_COPY                133             
00224 #define KEY_OPEN                134             
00225 #define KEY_PASTE               135             
00226 #define KEY_FIND                136             
00227 #define KEY_CUT                 137             
00228 #define KEY_HELP                138             
00229 #define KEY_MENU                139             
00230 #define KEY_CALC                140             
00231 #define KEY_SETUP               141             
00232 #define KEY_SLEEP               142             
00233 #define KEY_WAKEUP              143             
00234 #define KEY_FILE                144             
00235 #define KEY_SENDFILE            145             
00236 #define KEY_DELETEFILE          146             
00237 #define KEY_XFER                147             
00238 #define KEY_PROG1               148             
00239 #define KEY_PROG2               149             
00240 #define KEY_WWW                 150             
00241 #define KEY_MSDOS               151             
00242 #define KEY_COFFEE              152             
00243 #define KEY_DIRECTION           153             
00244 #define KEY_CYCLEWINDOWS        154             
00245 #define KEY_MAIL                155
00246 #define KEY_BOOKMARKS           156
00247 #define KEY_COMPUTER            157
00248 #define KEY_BACK                158
00249 #define KEY_FORWARD             159
00250 #define KEY_CLOSECD             160             
00251 #define KEY_EJECTCD             161             
00252 #define KEY_EJECTCLOSECD        162             
00253 #define KEY_NEXTSONG            163             
00254 #define KEY_PLAYPAUSE           164             
00255 #define KEY_PREVIOUSSONG        165             
00256 #define KEY_STOPCD              166             
00257 #define KEY_RECORD              167             
00258 #define KEY_REWIND              168             
00259 #define KEY_PHONE               169
00260 
00261 #define KEY_CONFIG              171
00262 #define KEY_HOMEPAGE            172
00263 #define KEY_REFRESH             173
00264 #define KEY_EXIT                174
00265 #define KEY_MOVE                175
00266 #define KEY_EDIT                176
00267 #define KEY_SCROLLUP            177
00268 #define KEY_SCROLLDOWN          178
00269 #define KEY_KPLEFTPAREN         179
00270 #define KEY_KPRIGHTPAREN        180
00271 
00272 #define KEY_INTL1               181
00273 #define KEY_INTL2               182
00274 #define KEY_INTL3               183
00275 #define KEY_INTL4               184
00276 #define KEY_INTL5               185
00277 #define KEY_INTL6               186
00278 #define KEY_INTL7               187
00279 #define KEY_INTL8               188
00280 #define KEY_INTL9               189
00281 #define KEY_LANG1               190
00282 #define KEY_LANG2               191
00283 #define KEY_LANG3               192
00284 #define KEY_LANG4               193
00285 #define KEY_LANG5               194
00286 #define KEY_LANG6               195
00287 #define KEY_LANG7               196
00288 #define KEY_LANG8               197
00289 #define KEY_LANG9               198
00290 
00291 #define KEY_UNKNOWN             200
00292 
00293 #define BTN_MISC                0x100
00294 #define BTN_0                   0x100
00295 #define BTN_1                   0x101
00296 #define BTN_2                   0x102
00297 #define BTN_3                   0x103
00298 #define BTN_4                   0x104
00299 #define BTN_5                   0x105
00300 #define BTN_6                   0x106
00301 #define BTN_7                   0x107
00302 #define BTN_8                   0x108
00303 #define BTN_9                   0x109
00304 
00305 #define BTN_MOUSE               0x110
00306 #define BTN_LEFT                0x110
00307 #define BTN_RIGHT               0x111
00308 #define BTN_MIDDLE              0x112
00309 #define BTN_SIDE                0x113
00310 #define BTN_EXTRA               0x114
00311 #define BTN_FORWARD             0x115
00312 #define BTN_BACK                0x116
00313 
00314 #define BTN_JOYSTICK            0x120
00315 #define BTN_TRIGGER             0x120
00316 #define BTN_THUMB               0x121
00317 #define BTN_THUMB2              0x122
00318 #define BTN_TOP                 0x123
00319 #define BTN_TOP2                0x124
00320 #define BTN_PINKIE              0x125
00321 #define BTN_BASE                0x126
00322 #define BTN_BASE2               0x127
00323 #define BTN_BASE3               0x128
00324 #define BTN_BASE4               0x129
00325 #define BTN_BASE5               0x12a
00326 #define BTN_BASE6               0x12b
00327 
00328 #define BTN_GAMEPAD             0x130
00329 #define BTN_A                   0x130
00330 #define BTN_B                   0x131
00331 #define BTN_C                   0x132
00332 #define BTN_X                   0x133
00333 #define BTN_Y                   0x134
00334 #define BTN_Z                   0x135
00335 #define BTN_TL                  0x136
00336 #define BTN_TR                  0x137
00337 #define BTN_TL2                 0x138
00338 #define BTN_TR2                 0x139
00339 #define BTN_SELECT              0x13a
00340 #define BTN_START               0x13b
00341 #define BTN_MODE                0x13c
00342 
00343 #define BTN_DIGI                0x140
00344 #define BTN_TOOL_PEN            0x140
00345 #define BTN_TOOL_RUBBER         0x141
00346 #define BTN_TOOL_BRUSH          0x142
00347 #define BTN_TOOL_PENCIL         0x143
00348 #define BTN_TOOL_AIRBRUSH       0x144
00349 #define BTN_TOOL_FINGER         0x145
00350 #define BTN_TOOL_MOUSE          0x146
00351 #define BTN_TOOL_LENS           0x147
00352 #define BTN_TOUCH               0x14a
00353 #define BTN_STYLUS              0x14b
00354 #define BTN_STYLUS2             0x14c
00355 
00356 #define KEY_MAX                 0x1ff
00357 
00358 /*
00359  * Relative axes
00360  */
00361 
00362 #define REL_X                   0x00
00363 #define REL_Y                   0x01
00364 #define REL_Z                   0x02
00365 #define REL_HWHEEL              0x06
00366 #define REL_DIAL                0x07
00367 #define REL_WHEEL               0x08
00368 #define REL_MISC                0x09
00369 #define REL_MAX                 0x0f
00370 
00371 /*
00372  * Absolute axes
00373  */
00374 
00375 #define ABS_X                   0x00
00376 #define ABS_Y                   0x01
00377 #define ABS_Z                   0x02
00378 #define ABS_RX                  0x03
00379 #define ABS_RY                  0x04
00380 #define ABS_RZ                  0x05
00381 #define ABS_THROTTLE            0x06
00382 #define ABS_RUDDER              0x07
00383 #define ABS_TL                  0x08
00384 #define ABS_TR                  0x09
00385 #define ABS_HAT0X               0x10
00386 #define ABS_HAT0Y               0x11
00387 #define ABS_HAT1X               0x12
00388 #define ABS_HAT1Y               0x13
00389 #define ABS_HAT2X               0x14
00390 #define ABS_HAT2Y               0x15
00391 #define ABS_HAT3X               0x16
00392 #define ABS_HAT3Y               0x17
00393 #define ABS_PRESSURE            0x18
00394 #define ABS_DISTANCE            0x19
00395 #define ABS_TILT_X              0x1a
00396 #define ABS_TILT_Y              0x1b
00397 #define ABS_MISC                0x1c
00398 #define ABS_MAX                 0x1f
00399 
00400 /*
00401  * LEDs
00402  */
00403 
00404 #define LED_NUML                0x00
00405 #define LED_CAPSL               0x01
00406 #define LED_SCROLLL             0x02
00407 #define LED_COMPOSE             0x03
00408 #define LED_KANA                0x04
00409 #define LED_MAX                 0x0f
00410 
00411 /*
00412  * Autorepeat values
00413  */
00414 
00415 #define REP_DELAY               0x00
00416 #define REP_PERIOD              0x01
00417 #define REP_MAX                 0x01
00418 
00419 /*
00420  * Sounds
00421  */
00422 
00423 #define SND_CLICK               0x00
00424 #define SND_BELL                0x01
00425 #define SND_MAX                 0x07
00426 
00427 /*
00428  * IDs.
00429  */
00430 
00431 #define ID_BUS                  0
00432 #define ID_VENDOR               1
00433 #define ID_PRODUCT              2
00434 #define ID_VERSION              3
00435 
00436 #define BUS_PCI                 0x01
00437 #define BUS_ISAPNP              0x02
00438 #define BUS_USB                 0x03
00439 
00440 #define BUS_ISA                 0x10
00441 #define BUS_I8042               0x11
00442 #define BUS_XTKBD               0x12
00443 #define BUS_RS232               0x13
00444 #define BUS_GAMEPORT            0x14
00445 #define BUS_PARPORT             0x15
00446 #define BUS_AMIGA               0x16
00447 #define BUS_ADB                 0x17
00448 
00449 #ifdef __KERNEL__
00450 
00451 /*
00452  * In-kernel definitions.
00453  */
00454 
00455 #include <linux/sched.h>
00456 #include <linux/devfs_fs_kernel.h>
00457 
00458 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
00459 #define BIT(x)  (1UL<<((x)%BITS_PER_LONG))
00460 #define LONG(x) ((x)/BITS_PER_LONG)
00461 
00462 struct input_dev {
00463 
00464         void *private;
00465 
00466         int number;
00467         char *name;
00468         unsigned short idbus;
00469         unsigned short idvendor;
00470         unsigned short idproduct;
00471         unsigned short idversion;
00472 
00473         unsigned long evbit[NBITS(EV_MAX)];
00474         unsigned long keybit[NBITS(KEY_MAX)];
00475         unsigned long relbit[NBITS(REL_MAX)];
00476         unsigned long absbit[NBITS(ABS_MAX)];
00477         unsigned long ledbit[NBITS(LED_MAX)];
00478         unsigned long sndbit[NBITS(SND_MAX)];
00479 
00480         unsigned int keycodemax;
00481         unsigned int keycodesize;
00482         void *keycode;
00483 
00484         unsigned int repeat_key;
00485         struct timer_list timer;
00486 
00487         int abs[ABS_MAX + 1];
00488         int rep[REP_MAX + 1];
00489 
00490         unsigned long key[NBITS(KEY_MAX)];
00491         unsigned long led[NBITS(LED_MAX)];
00492         unsigned long snd[NBITS(SND_MAX)];
00493         
00494         int absmax[ABS_MAX + 1];
00495         int absmin[ABS_MAX + 1];
00496         int absfuzz[ABS_MAX + 1];
00497         int absflat[ABS_MAX + 1];
00498 
00499         int (*open)(struct input_dev *dev);
00500         void (*close)(struct input_dev *dev);
00501         int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
00502 
00503         struct input_handle *handle;
00504         struct input_dev *next;
00505 };
00506 
00507 struct input_handler {
00508 
00509         void *private;
00510 
00511         void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
00512         struct input_handle* (*connect)(struct input_handler *handler, struct input_dev *dev);
00513         void (*disconnect)(struct input_handle *handle);
00514 
00515         struct file_operations *fops;
00516         int minor;
00517 
00518         struct input_handle *handle;
00519         struct input_handler *next;
00520 };
00521 
00522 struct input_handle {
00523 
00524         void *private;
00525 
00526         int open;
00527         
00528         struct input_dev *dev;
00529         struct input_handler *handler;
00530 
00531         struct input_handle *dnext;
00532         struct input_handle *hnext;
00533 };
00534 
00535 void input_register_device(struct input_dev *);
00536 void input_unregister_device(struct input_dev *);
00537 
00538 void input_register_handler(struct input_handler *);
00539 void input_unregister_handler(struct input_handler *);
00540 
00541 int input_open_device(struct input_handle *);
00542 void input_close_device(struct input_handle *);
00543 
00544 devfs_handle_t input_register_minor(char *name, int minor, int minor_base);
00545 void input_unregister_minor(devfs_handle_t handle);
00546 
00547 void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
00548 
00549 #define input_report_key(a,b,c) input_event(a, EV_KEY, b, !!(c))
00550 #define input_report_rel(a,b,c) input_event(a, EV_REL, b, c)
00551 #define input_report_abs(a,b,c) input_event(a, EV_ABS, b, c)
00552 
00553 #endif
00554 #endif