Commit c54667d3 authored by kernc's avatar kernc

Added -d switch for custom device selection and documented it in the manual.

git-svn-id: https://logkeys.googlecode.com/svn/trunk@20 c501e62c-e7d1-11de-a198-37193048d1ed
parent f3002c7b
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
logkeys \- a GNU/Linux keylogger that works! logkeys \- a GNU/Linux keylogger that works!
.SH SYNOPSIS .SH SYNOPSIS
.B logkeys .B logkeys
\fB-s\fR [\fB-m \fIkeymap\fR|\fB-u\fR] [\fB-o \fIlogfile\fR] [\fB--no-func-keys\fR] \fB-s\fR [\fB-m \fIkeymap\fR|\fB-u\fR] [\fB-o \fIlogfile\fR] [\fB-d \fIdevice\fR] [\fB--no-func-keys\fR]
.br .br
.B logkeys .B logkeys
\fB-k\fR \fB-k\fR
...@@ -50,6 +50,11 @@ See also \fBKEYMAP FORMAT\fR section. ...@@ -50,6 +50,11 @@ See also \fBKEYMAP FORMAT\fR section.
.IP .IP
\fB-m\fR and \fB-u\fR option are mutually exclusive. \fB-m\fR and \fB-u\fR option are mutually exclusive.
.TP .TP
\fB-d\fR, \fB-\-device\fR=\fIdevice\fR
Use \fIdevice\fR as keyboard input event device instead of \fI/dev/input/eventX\fR default.
.IP
You can determine the keyboard device to be used by examining \fI/proc/bus/input/devices\fR.
.TP
\fB-u\fR, \fB-\-us-keymap\fR \fB-u\fR, \fB-\-us-keymap\fR
This option makes logkeys interpret keys as on standard US keyboard. This option makes logkeys interpret keys as on standard US keyboard.
.IP .IP
......
...@@ -43,11 +43,13 @@ void usage() { ...@@ -43,11 +43,13 @@ void usage() {
" -o, --output=FILE log output to FILE [" DEFAULT_LOG_FILE "]\n" " -o, --output=FILE log output to FILE [" DEFAULT_LOG_FILE "]\n"
" -u, --us-keymap use en_US keymap instead of configured default\n" " -u, --us-keymap use en_US keymap instead of configured default\n"
" -k, --kill kill running logkeys process\n" " -k, --kill kill running logkeys process\n"
" -d, --device=FILE input event device [" INPUT_EVENT_PATH "X]\n"
" -?, --help print this help\n" " -?, --help print this help\n"
" --export-keymap=FILE export configured keymap to FILE and exit\n" " --export-keymap=FILE export configured keymap to FILE and exit\n"
" --no-func-keys don't log function keys, only character keys\n" " --no-func-keys don't log function keys, only character keys\n"
"\n" "\n"
"Examples: logkeys -s -m mylang.map -o ~/.secret/keys.log\n" "Examples: logkeys -s -m mylang.map -o ~/.secret/keys.log\n"
" logkeys -s -d /dev/input/event6\n"
" logkeys -k\n" " logkeys -k\n"
"\n" "\n"
"logkeys version: " PACKAGE_VERSION "\n" "logkeys version: " PACKAGE_VERSION "\n"
...@@ -151,6 +153,7 @@ int main(int argc, char **argv) { ...@@ -151,6 +153,7 @@ int main(int argc, char **argv) {
char *log_filename = (char*) DEFAULT_LOG_FILE; // default log file char *log_filename = (char*) DEFAULT_LOG_FILE; // default log file
char log_file_path[512]; // don't use paths longer than 512 B !! char log_file_path[512]; // don't use paths longer than 512 B !!
char *keymap_filename = NULL; // path to keymap file to be used char *keymap_filename = NULL; // path to keymap file to be used
char *device_filename = NULL; // path to input event device if given with -d switch
{ // process options and arguments { // process options and arguments
...@@ -160,9 +163,10 @@ int main(int argc, char **argv) { ...@@ -160,9 +163,10 @@ int main(int argc, char **argv) {
{"output", required_argument, 0, 'o'}, {"output", required_argument, 0, 'o'},
{"us-keymap", no_argument, 0, 'u'}, {"us-keymap", no_argument, 0, 'u'},
{"kill", no_argument, 0, 'k'}, {"kill", no_argument, 0, 'k'},
{"device", required_argument, 0, 'd'},
{"help", no_argument, 0, '?'}, {"help", no_argument, 0, '?'},
#define EXPORT_KEYMAP_INDEX 6 #define EXPORT_KEYMAP_INDEX 7
{"export-keymap", required_argument, &flag_export, 1}, // option_index is 6 {"export-keymap", required_argument, &flag_export, 1}, // option_index is 7
{"no-func-keys", no_argument, &flag_nofunc, 1}, {"no-func-keys", no_argument, &flag_nofunc, 1},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
...@@ -170,13 +174,14 @@ int main(int argc, char **argv) { ...@@ -170,13 +174,14 @@ int main(int argc, char **argv) {
char c; char c;
int option_index; int option_index;
while ((c = getopt_long(argc, argv, "sm:o:uk?", long_options, &option_index)) != -1) while ((c = getopt_long(argc, argv, "sm:o:ukd:?", long_options, &option_index)) != -1)
switch (c) { switch (c) {
case 's': flag_start = true; break; case 's': flag_start = true; break;
case 'm': flag_keymap = true; keymap_filename = optarg; break; case 'm': flag_keymap = true; keymap_filename = optarg; break;
case 'o': log_filename = optarg; break; case 'o': log_filename = optarg; break;
case 'u': flag_us_keymap = true; break; case 'u': flag_us_keymap = true; break;
case 'k': flag_kill = true; break; case 'k': flag_kill = true; break;
case 'd': device_filename = optarg; break;
case 0 : case 0 :
if (option_index == EXPORT_KEYMAP_INDEX) if (option_index == EXPORT_KEYMAP_INDEX)
...@@ -385,6 +390,9 @@ int main(int argc, char **argv) { ...@@ -385,6 +390,9 @@ int main(int argc, char **argv) {
#ifndef INPUT_EVENT_DEVICE // sometimes X in /dev/input/eventX is different from one reboot to another #ifndef INPUT_EVENT_DEVICE // sometimes X in /dev/input/eventX is different from one reboot to another
char *INPUT_EVENT_DEVICE;
if (device_filename == NULL) { // no device given with -d switch, determine it automatically
// extract input number from /proc/bus/input/devices (I don't know how to do it better. If you have an idea, please let me know.) // extract input number from /proc/bus/input/devices (I don't know how to do it better. If you have an idea, please let me know.)
std::string output = exec("grep Name /proc/bus/input/devices | grep -nE '[Kk]eyboard|kbd'"); std::string output = exec("grep Name /proc/bus/input/devices | grep -nE '[Kk]eyboard|kbd'");
if (output == "ERR") { // if pipe errors, exit if (output == "ERR") { // if pipe errors, exit
...@@ -397,7 +405,9 @@ int main(int argc, char **argv) { ...@@ -397,7 +405,9 @@ int main(int argc, char **argv) {
input_fd_filename << INPUT_EVENT_PATH; input_fd_filename << INPUT_EVENT_PATH;
input_fd_filename << (atoi(output.c_str()) - 1); input_fd_filename << (atoi(output.c_str()) - 1);
const char *INPUT_EVENT_DEVICE = input_fd_filename.str().c_str(); INPUT_EVENT_DEVICE = (char*)input_fd_filename.str().c_str();
} else INPUT_EVENT_DEVICE = device_filename; // event device supplied as -d argument
#endif//INPUT_EVENT_DEVICE #endif//INPUT_EVENT_DEVICE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment