Ak si trosku zbehly, skus si skompilovat tento program a spustat ho ako sluzbu. Makefile:
mpckbd: mpckbd.c Makefile
gcc -o mpckbd mpckbd.c -O3 $(INCLUDES)
mpckbd.c:
#include <linux/input.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
void parse(char *line, char **argv);
void run(char *cmd, char *params);
int main() {
char *mpc,*amixer,*conf;
conf="/etc/mpckbd.conf";
mpc="mpc";
amixer="amixer";
int fd;
char cmd[1024];
char key_fav[80];
char key_a[80];
if ((fd = open("/dev/input/event8", O_RDONLY)) < 0) {
perror("evdev open");
_exit(1);
}
struct input_event event;
FILE *file = fopen(conf , "r");
if ( file != NULL ) {
if ( fgets(key_fav, sizeof key_fav, file) != NULL ) {
char *newline = strchr(key_fav, '\n');
if ( newline != NULL ) {
*newline = '\0';
}
}
if ( fgets(key_a, sizeof key_a, file) != NULL ) {
char *newline = strchr(key_a, '\n');
if ( newline != NULL ) {
*newline = '\0';
}
}
fclose(file);
}
while (read(fd, &event, sizeof(event)) > 0) {
if (event.type != EV_KEY) continue;
if (event.value != EV_KEY) continue;
printf("type=%i value=%i code=%i \n",event.type,event.value,event.code); //vypis co bolo stlacene
strcpy(cmd,"");
switch (event.code) {
case 114://MPCKBD_MINUS:
run(amixer,"set Master playback 2dB-"); break;
case 113://MPCKBD_MUTE:
run(amixer,"set Master toggle"); break;
case 115://MPCKBD_PLUS:
run(amixer,"set Master playback 2dB+"); break;
case 165://MPCKBD_PREV:
run(mpc,"prev"); break;
case 166://MPCKBD_STOP:
run(mpc,"stop"); break;
case 164://MPCKBD_TOGGLE:
run(mpc,"toggle"); break;
case 163://MPCKBD_NEXT:
run(mpc,"next"); break;
case 156://MPCKBD_FAV:
run(mpc,key_fav); break;
case 140://MPCKBD_ADR:
run(mpc,key_a); break;
case 159://MPCKBD_FORWARD:
run(mpc,"seek +00:00:10"); break;
case 158://MPCKBD_BACK:
run(mpc,"seek -00:00:10"); break;
}
}
return 1;
}
void parse(char *line, char **argv)
{
while (*line!='\0') {
while (*line==' ' || *line=='\t' || *line=='\n')
*line++ = '\0';
*argv++ = line;
while (*line!='\0' && *line!=' ' && *line!='\t' && *line!='\n')
line++;
}
*argv = '\0';
}
void run(char *cmd, char *params)
{
char line[1024];
strcpy(line,cmd);
strcat(line," ");
strcat(line,params);
char *argv[64];
parse(line,argv);
if (fork() != 0) return;
close(0);
close(1);
close(2);
execvp(*argv,argv);
_exit(1);
}
Kody za riadkom "switch (event.code) {" si mozes lubovolne menit, pridavat, ci mazat. Potom len program znovu skompilujes a mozes pouzit.