added -h flag
This commit is contained in:
parent
213db3cee5
commit
8ad875b311
3
hkd.1
3
hkd.1
@ -7,6 +7,7 @@ hkd \- simple HotKey Daemon
|
|||||||
.SY hkd
|
.SY hkd
|
||||||
.OP \-v
|
.OP \-v
|
||||||
.OP \-d
|
.OP \-d
|
||||||
|
.OP \-h
|
||||||
.OP \-c file
|
.OP \-c file
|
||||||
.YS
|
.YS
|
||||||
|
|
||||||
@ -27,6 +28,8 @@ change acting as a crude keylogger :^)
|
|||||||
.IP \-d
|
.IP \-d
|
||||||
dump, used for debugging, it prints the whole hotkey list along with the
|
dump, used for debugging, it prints the whole hotkey list along with the
|
||||||
information about the hotkeys (matching type, keys and associated command).
|
information about the hotkeys (matching type, keys and associated command).
|
||||||
|
.IP \-h
|
||||||
|
prints help message and exits
|
||||||
.IP "\-c file"
|
.IP "\-c file"
|
||||||
override default configuration file location, instead using the specified
|
override default configuration file location, instead using the specified
|
||||||
.I file
|
.I file
|
||||||
|
52
hkd.c
52
hkd.c
@ -249,6 +249,7 @@ void parse_config_file (void);
|
|||||||
void update_descriptors_list (int **, int *);
|
void update_descriptors_list (int **, int *);
|
||||||
void remove_lock (void);
|
void remove_lock (void);
|
||||||
void die (const char *, ...);
|
void die (const char *, ...);
|
||||||
|
void usage (void);
|
||||||
int prepare_epoll (int *, int, int);
|
int prepare_epoll (int *, int, int);
|
||||||
unsigned short key_to_code (char *);
|
unsigned short key_to_code (char *);
|
||||||
const char * code_to_name (unsigned int);
|
const char * code_to_name (unsigned int);
|
||||||
@ -270,26 +271,8 @@ int main (int argc, char *argv[])
|
|||||||
struct input_event event;
|
struct input_event event;
|
||||||
struct key_buffer pb = {{0}, 0}; // Pressed keys buffer
|
struct key_buffer pb = {{0}, 0}; // Pressed keys buffer
|
||||||
|
|
||||||
/* Check if hkd is already running */
|
|
||||||
lock_file_descriptor = open(LOCK_FILE, O_RDWR | O_CREAT, 0600);
|
|
||||||
if (lock_file_descriptor < 0)
|
|
||||||
die("Can't open lock file:");
|
|
||||||
fl.l_start = 0;
|
|
||||||
fl.l_len = 0;
|
|
||||||
fl.l_type = F_WRLCK;
|
|
||||||
fl.l_whence = SEEK_SET;
|
|
||||||
if (fcntl(lock_file_descriptor, F_SETLK, &fl) < 0)
|
|
||||||
die("hkd is already running");
|
|
||||||
atexit(remove_lock);
|
|
||||||
|
|
||||||
/* Handle SIGINT */
|
|
||||||
dead = 0;
|
|
||||||
memset(&action, 0, sizeof(action));
|
|
||||||
action.sa_handler = int_handler;
|
|
||||||
sigaction(SIGINT, &action, NULL);
|
|
||||||
|
|
||||||
/* Parse command line arguments */
|
/* Parse command line arguments */
|
||||||
while ((opc = getopt(argc, argv, "vc:d")) != -1) {
|
while ((opc = getopt(argc, argv, "vc:dh")) != -1) {
|
||||||
switch (opc) {
|
switch (opc) {
|
||||||
case 'v':
|
case 'v':
|
||||||
vflag = 1;
|
vflag = 1;
|
||||||
@ -303,13 +286,34 @@ int main (int argc, char *argv[])
|
|||||||
case 'd':
|
case 'd':
|
||||||
dump = 1;
|
dump = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
usage();
|
||||||
|
break;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Handle SIGINT */
|
||||||
|
dead = 0;
|
||||||
|
memset(&action, 0, sizeof(action));
|
||||||
|
action.sa_handler = int_handler;
|
||||||
|
sigaction(SIGINT, &action, NULL);
|
||||||
|
|
||||||
/* Parse config file */
|
/* Parse config file */
|
||||||
parse_config_file();
|
parse_config_file();
|
||||||
|
|
||||||
|
/* Check if hkd is already running */
|
||||||
|
lock_file_descriptor = open(LOCK_FILE, O_RDWR | O_CREAT, 0600);
|
||||||
|
if (lock_file_descriptor < 0)
|
||||||
|
die("Can't open lock file:");
|
||||||
|
fl.l_start = 0;
|
||||||
|
fl.l_len = 0;
|
||||||
|
fl.l_type = F_WRLCK;
|
||||||
|
fl.l_whence = SEEK_SET;
|
||||||
|
if (fcntl(lock_file_descriptor, F_SETLK, &fl) < 0)
|
||||||
|
die("hkd is already running");
|
||||||
|
atexit(remove_lock);
|
||||||
|
|
||||||
/* If a dump is requested print the hotkey list then exit */
|
/* If a dump is requested print the hotkey list then exit */
|
||||||
if (dump) {
|
if (dump) {
|
||||||
printf("DUMPING HOTKEY LIST\n\n");
|
printf("DUMPING HOTKEY LIST\n\n");
|
||||||
@ -947,3 +951,13 @@ const char * code_to_name (unsigned int code)
|
|||||||
}
|
}
|
||||||
return "Key not recognized";
|
return "Key not recognized";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void usage (void)
|
||||||
|
{
|
||||||
|
puts("Usage: hkd [-vdh] [-c file]\n"
|
||||||
|
"\t-v verbose, prints all the key presses and debug information\n"
|
||||||
|
"\t-d dump, dumps the hotkey list and exits\n"
|
||||||
|
"\t-h prints this help message\n"
|
||||||
|
"\t-f file uses the specified file as config\n");
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user