added -q option

This commit is contained in:
mrbesen 2019-01-19 18:54:41 +01:00
parent 1bb82fa267
commit bd76593058
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
3 changed files with 15 additions and 8 deletions

View File

@ -19,6 +19,7 @@ struct arguments
bool kill; // stop keylogger, -k switch
bool us_keymap; // use default US keymap, -u switch
bool precise; // log with ms, -p switch
bool onlyms;
std::string logfile; // user-specified log filename, -o switch
std::string keymap; // user-specified keymap file, -m switch or --export-keymap
std::string device; // user-specified input event device, given with -d switch
@ -64,7 +65,7 @@ void process_command_line_arguments(int argc, char **argv)
int c;
int option_index;
while ((c = getopt_long(argc, argv, "sm:o:ukpd:?", long_options, &option_index)) != -1)
while ((c = getopt_long(argc, argv, "sm:o:ukpqd:?", long_options, &option_index)) != -1)
{
switch (c)
{
@ -75,7 +76,8 @@ void process_command_line_arguments(int argc, char **argv)
case 'k': args.kill = true; break;
case 'd': args.device = optarg; break;
case 'p': args.precise = true; break;
case 'q': args.precise = args.onlyms = true; break;
case 0 :
args.flags |= flags;
switch (flags)

View File

@ -25,7 +25,6 @@
#include <sys/socket.h>
#include <linux/input.h>
#include <chrono> // for precise time messureing
#include <iostream> //debug
#ifdef HAVE_CONFIG_H
# include <config.h> // include config produced from ./configure
@ -456,11 +455,16 @@ void init() {
std::string createStamp() {
std::chrono::time_point < std::chrono::system_clock > time = std::chrono::system_clock::now();
time_t cur_time = std::chrono::system_clock::to_time_t(time);
auto time_ms = std::chrono::duration_cast < std::chrono::milliseconds > (time - std::chrono::system_clock::from_time_t(cur_time));
char timestamp[32];
strftime(timestamp, sizeof(timestamp), TIME_FORMAT, localtime(&cur_time));
return std::string(timestamp) + std::to_string(time_ms.count()) + "ms : ";
auto time_ms = std::chrono::duration_cast < std::chrono::milliseconds > (time.time_since_epoch());
std::string out = "";
if(!args.onlyms) {
time_t cur_time = std::chrono::system_clock::to_time_t(time);
time_ms = std::chrono::duration_cast < std::chrono::milliseconds > (time - std::chrono::system_clock::from_time_t(cur_time));
char timestamp[32];
strftime(timestamp, sizeof(timestamp), TIME_FORMAT, localtime(&cur_time));
out = std::string(timestamp);
}
return out + std::to_string(time_ms.count()) + "ms : ";
}
int printBeginStamp(FILE* out) {

View File

@ -24,6 +24,7 @@ void usage()
" -k, --kill kill running logkeys process\n"
" -d, --device=FILE input event device [eventX from " INPUT_EVENT_PATH "]\n"
" -p, --precise add milliseconds to the timestamp and add a timestamp to every press\n"
" -q, only log the ms to create a esaier format for other programs to process"
" -?, --help print this help screen\n"
" --export-keymap=FILE export configured keymap to FILE and exit\n"
" --no-func-keys log only character keys\n"