File: evsend.cpp

package info (click to toggle)
xboxdrv 0.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,252 kB
  • sloc: cpp: 19,297; xml: 3,202; ansic: 507; python: 483; sh: 89; makefile: 34; ruby: 19
file content (52 lines) | stat: -rw-r--r-- 1,315 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <linux/input.h>

#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

/** Simple program to send events to /dev/input/eventX devices, useful
    for toggling LEDs and such */
int main(int argc, char** argv)
{
  if (argc != 5)
    {
      std::cout << "Usage: " << argv[0] << " DEVICE TYPE CODE VALUE" << std::endl;
    }
  else
    {
      const char* filename = argv[1];
      struct input_event event;
      event.type  = atoi(argv[2]);
      event.code  = atoi(argv[3]);
      event.value = atoi(argv[4]);

      int fd = open(filename, O_RDWR);
      if (fd < 0)        
        {
          std::cout << argv[0] << ": couldn't access: " << filename << ": " << strerror(errno) << std::endl;
        }
      else
        {
          if (write(fd, &event, sizeof(event)) != sizeof(event))
            {
              std::cout << argv[0] << ": write error: " << filename << ": " << strerror(errno) << std::endl;
            }
          else
            {
              // std::cout << "Send: Event(type: " << event.type << ", code: " << event.code << ", value: " << event.value << ")" << std::endl;
            }
          close(fd);
        }
    }

  return 0;
}

/* EOF */