Hardware Reference
In-Depth Information
277 /
278
Synthesize a button click :
279
up_down 1=up, 0=down
280
buttons 1=Left, 2=Middle, 4=Right
281
/
282 static void
283 uinput_click(int fd,int up_down,int buttons) {
284 static unsigned codes[] = {BTN_LEFT, BTN_MIDDLE, BTN_RIGHT};
285 struct input_event ev;
286 int x;
287
288 memset(&ev,0,sizeof(ev));
289
290 /
291
Button down or up events:
292
/
293 for ( x=0; x < 3; ++x ) {
294 ev.type = EV_KEY;
295 ev.value = up_down; /
Button Up or down
/
296 if ( buttons & (1 << x) ) { /
Button 0, 1 or 2
/
297 ev.code = codes[x];
298 write(fd,&ev,sizeof(ev));
299 }
300 }
301 }
302
303 /
304
Synthesize relative mouse movement:
305
/
306 static void
307 uinput_movement(int fd,int x,int y) {
308 struct input_event ev;
309 int rc;
310
311 memset(&ev,0,sizeof(ev));
312 ev.type = EV_REL;
313 ev.code = REL_X;
314 ev.value = x;
315
316 rc = write(fd,&ev,sizeof(ev));
317 assert(rc == sizeof(ev));
318
319 ev.code = REL_Y;
320 ev.value = y;
321 rc = write(fd,&ev,sizeof(ev));
322 assert(rc == sizeof(ev));
323 }
324
Search WWH ::




Custom Search