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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
* keytest.c --- ESE Key Daemon --- Keycode Daemon for Funny/Function Keys.
*
* Taps /dev/input/event<number> and reports pressed keys names.
*
* $Id: keytest.c 63 2010-07-04 20:23:51Z kb $
*
* Based on code from funky.c released under the GNU Public License
* by Rick van Rein.
*
* (c) 2000 Rick van Rein.
* (c) 2004 Krzysztof Burghardt.
*
* Released under the GNU Public License.
*/
#include "esekey.h"
FILE *funkey = NULL;
void cleanup ()
{
fclose (funkey);
}
void signal_handler (int x)
{
printf ("\n\nCaught signal %d, exiting...\n", x);
cleanup ();
exit(x);
}
void register_signal_handlers (void)
{
signal (SIGHUP, signal_handler);
signal (SIGINT, signal_handler);
signal (SIGQUIT, signal_handler);
signal (SIGILL, signal_handler);
signal (SIGTRAP, signal_handler);
signal (SIGABRT, signal_handler);
signal (SIGIOT, signal_handler);
signal (SIGFPE, signal_handler);
signal (SIGKILL, signal_handler);
signal (SIGSEGV, signal_handler);
signal (SIGPIPE, signal_handler);
signal (SIGTERM, signal_handler);
signal (SIGSTOP, signal_handler);
signal (SIGUSR1, SIG_IGN);
}
int main (int argc, char *argv[])
{
short int device = 0;
char *device_name = NULL;
char *key = NULL;
struct input_event ev;
printf ("keytest (%s, %s)\n", PACKAGE_STRING, PACKAGE_VERSION_SVN_REV);
if (argc > 1)
{
device_name = argv[1];
}
else
{
printf ("\n(input device name as 1st option override autodetection)\n");
switch (check_handlers ())
{
case -1:
printf ("%s: cannot open %s\n", argv[0], INPUT_HANDLERS);
return -1;
case -2:
printf ("%s: evdev handler not found in %s\n", argv[0],
INPUT_HANDLERS);
return -2;
}
switch (device = find_input_dev ())
{
case -1:
printf ("%s: evdev for keyboard not found in %s\n", argv[0],
INPUT_HANDLERS);
return -3;
default:
asprintf (&device_name, "%s%hu", EVENT_DEVICE, device);
}
}
if (!(funkey = fopen (device_name, "r")))
{
printf ("%s: can`t open %s\n", argv[0], device_name);
return -4;
}
printf ("\nPres ANY (fun)key... or Ctrl-C to exit...\n\n");
register_signal_handlers();
while (fread (&ev, sizeof (struct input_event), 1, funkey))
{
if (ev.code == 28 && ev.type == EV_KEY && ev.value == 1)
{
printf ("\n");
fclose (funkey);
return 0;
}
if ((key = parse (ev)) != NULL)
{
printf ("%s ", key);
fflush (stdout);
}
}
cleanup ();
return 0;
}
|