Permalink
Checking mergeability…
Don’t worry, you can still create the pull request.
Comparing changes
Open a pull request
- 2 commits
- 3 files changed
- 0 commit comments
- 1 contributor
Unified
Split
Showing
with
582 additions
and 1 deletion.
- +37 −0 .vscode/settings.json
- +30 −1 src/logkeys.cc
- +515 −0 test.log
| @@ -0,0 +1,37 @@ | |||
| { | |||
| "files.associations": { | |||
| "array": "cpp", | |||
| "*.tcc": "cpp", | |||
| "cctype": "cpp", | |||
| "clocale": "cpp", | |||
| "cmath": "cpp", | |||
| "csignal": "cpp", | |||
| "cstdint": "cpp", | |||
| "cstdio": "cpp", | |||
| "cstdlib": "cpp", | |||
| "cstring": "cpp", | |||
| "cwchar": "cpp", | |||
| "cwctype": "cpp", | |||
| "unordered_map": "cpp", | |||
| "vector": "cpp", | |||
| "exception": "cpp", | |||
| "fstream": "cpp", | |||
| "initializer_list": "cpp", | |||
| "iosfwd": "cpp", | |||
| "istream": "cpp", | |||
| "limits": "cpp", | |||
| "new": "cpp", | |||
| "optional": "cpp", | |||
| "ostream": "cpp", | |||
| "sstream": "cpp", | |||
| "stdexcept": "cpp", | |||
| "streambuf": "cpp", | |||
| "string_view": "cpp", | |||
| "system_error": "cpp", | |||
| "type_traits": "cpp", | |||
| "tuple": "cpp", | |||
| "typeinfo": "cpp", | |||
| "utility": "cpp", | |||
| "numeric": "cpp" | |||
| } | |||
| } | |||
| @@ -49,6 +49,8 @@ | |||
| #define COMMAND_STR_DUMPKEYS ( EXE_DUMPKEYS " -n | " EXE_GREP " '^\\([[:space:]]shift[[:space:]]\\)*\\([[:space:]]altgr[[:space:]]\\)*keycode'" ) | |||
| #define COMMAND_STR_GET_PID ( (std::string(EXE_PS " ax | " EXE_GREP " '") + program_invocation_name + "' | " EXE_GREP " -v grep").c_str() ) | |||
| #define COMMAND_STR_CAPSLOCK_STATE ("{ { xset q 2>/dev/null | grep -q -E 'Caps Lock: +on'; } || { setleds 2>/dev/null | grep -q 'CapsLock on'; }; } && echo on") | |||
| #define COMMAND_GET_ACTIVE_WINDOW std::string("xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) WM_NAME").c_str() | |||
| #define COMMAND_GET_ACTIVE_WINDOW_BIS "xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) WM_NAME | sed -nr 's/.*= \"(.*)\"$/\1/p'" | |||
|
|
|||
| #define INPUT_EVENT_PATH "/dev/input/" // standard path | |||
| #define DEFAULT_LOG_FILE "/var/log/logkeys.log" | |||
| @@ -76,6 +78,22 @@ std::string execute(const char* cmd) | |||
| return result; | |||
| } | |||
|
|
|||
| std::string GetStdoutFromCommand(std::string cmd) | |||
| { | |||
| std::string data; | |||
| FILE * stream; | |||
| const int max_buffer = 256; | |||
| char buffer[max_buffer]; | |||
| cmd.append(" 2>&1"); | |||
|
|
|||
| stream = popen(cmd.c_str(), "r"); | |||
| if (stream) { | |||
| while (!feof(stream)) | |||
| if (fgets(buffer, max_buffer, stream) != NULL) data.append(buffer); | |||
| pclose(stream); | |||
| } | |||
| return data; | |||
| } | |||
|
|
|||
| int input_fd = -1; // input event device file descriptor; global so that signal_handler() can access it | |||
|
|
|||
| @@ -577,12 +595,23 @@ int main(int argc, char **argv) | |||
| (ctrl_in_effect && (scan_code == KEY_C || scan_code == KEY_D))) { | |||
| if (ctrl_in_effect) | |||
| inc_size += fprintf(out, "%lc", char_keys[to_char_keys_index(scan_code)]); // log C or D | |||
| if (args.flags & FLAG_NO_TIMESTAMPS) | |||
| if (args.flags & FLAG_NO_TIMESTAMPS) { | |||
| // add current active window | |||
| std::string active_window = execute(COMMAND_GET_ACTIVE_WINDOW); | |||
| inc_size += fprintf(out, " [ %s ]", active_window.c_str()); | |||
| inc_size += fprintf(out, "\n"); | |||
| } | |||
| else { | |||
| // add current active window | |||
| std::string active_window = execute(COMMAND_GET_ACTIVE_WINDOW); | |||
| inc_size += fprintf(out, " [ %s ]", active_window.c_str()); | |||
| strftime(timestamp, sizeof(timestamp), "\n" TIME_FORMAT, localtime(&event.time.tv_sec)); | |||
| inc_size += fprintf(out, "%s", timestamp); // then newline and timestamp | |||
| } | |||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
| if (inc_size > 0) file_size += inc_size; | |||
| continue; // but don't log "<Enter>" | |||
| } | |||
Oops, something went wrong.