Skip to content

Commit

Permalink
Remove "-time": instead recommend an external tool
Browse files Browse the repository at this point in the history
Undoing my unnecessary feature creep.
  • Loading branch information
anko committed Feb 16, 2016
1 parent 09f581e commit 5f73713
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
12 changes: 8 additions & 4 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Flags you can pass (all optional):
- `-delay <nanosec>`: delay between polls to the keyboard (default `10000000`;
that's 100ms)
- `-up`: also prepend key-ups (default: don't)
- `-time`: also append epoch timestamps (default: don't)
- `-help`: print usage hints and exit

Then just type as you would usually. Interrupt signal (`C-c`) to end.
Expand All @@ -55,12 +54,17 @@ If you like spying on people (ethically, of course), [`xspy`][1] or
[`logkeys`][2] might be better for you. They use the modifier keys to infer
what was actually typed, so it's easier to read what's happening.

If you want to add timestamps to each line for logging purposes, I recommend
piping to the [moreutils package][3]'s `ts`. [These answers][4] feature
various other tools good for the purpose.

## License

[ISC][3].
[ISC][5].


[1]: http://www.freshports.org/security/xspy/
[2]: http://code.google.com/p/logkeys/
[3]: http://opensource.org/licenses/ISC
[Chi]: http://en.wikipedia.org/wiki/Chi's_Sweet_Home
[3]: http://joeyh.name/code/moreutils/
[4]: http://stackoverflow.com/questions/21564/is-there-a-unix-utility-to-prepend-timestamps-to-lines-of-text
[5]: http://opensource.org/licenses/ISC
17 changes: 4 additions & 13 deletions xkbcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
const char * DEFAULT_DISPLAY = ":0";
const int DEFAULT_DELAY = 10000000;
const bool DEFAULT_PRINT_UP = false;
const bool DEFAULT_PRINT_TIME = false;

typedef char KbBuffer[32];

Expand All @@ -24,14 +23,12 @@ static inline bool keyState(KbBuffer b, int key) {

int printUsage() {
printf("\
USAGE: xkbcat [-display <display>] [-delay <nanosec>] [-up] [-time]\n\
USAGE: xkbcat [-display <display>] [-delay <nanosec>] [-up]\n\
display target X display (default %s)\n\
delay polling frequency; nanoseconds (default %d)\n\
up also print key-ups (default %s)\n\
time also print timestamps (default %s)\n",
up also print key-ups (default %s)\n",
DEFAULT_DISPLAY, DEFAULT_DELAY,
(DEFAULT_PRINT_UP ? "yes" : "no"),
(DEFAULT_PRINT_TIME ? "yes" : "no") );
(DEFAULT_PRINT_UP ? "yes" : "no") );
exit(0);
}

Expand All @@ -40,15 +37,13 @@ int main(int argc, char * argv[]) {
const char * hostname = DEFAULT_DISPLAY;
int delay = DEFAULT_DELAY;
bool printKeyUps = DEFAULT_PRINT_UP;
bool printTimes = DEFAULT_PRINT_TIME;

// Get arguments
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-help")) printUsage();
else if (!strcmp(argv[i], "-display")) hostname = argv[++i];
else if (!strcmp(argv[i], "-delay")) delay = atoi(argv[++i]);
else if (!strcmp(argv[i], "-up")) printKeyUps = true;
else if (!strcmp(argv[i], "-time")) printTimes = true;
else { printf("Unexpected argument `%s`\n", argv[i]); printUsage(); }
}

Expand All @@ -71,8 +66,6 @@ int main(int argc, char * argv[]) {

while (1) { // Forever
XQueryKeymap(disp, *keys); // Fetch changed keys
long timestamp = 0;
if (printTimes) timestamp = (long)time(NULL);

for (int keyCode = 0; keyCode < sizeof(KbBuffer) * 8; keyCode++) {
bool stateBefore = keyState(*oldKeys, keyCode),
Expand All @@ -87,9 +80,7 @@ int main(int argc, char * argv[]) {
if (NULL == str) continue;

if (printKeyUps) printf("%s ", (stateNow ? "+" : "-"));
printf("%s", str);
if (printTimes) printf(" %ld", timestamp);
printf("\n");
printf("%s\n", str);
}
}
// Make sure the data is sent right away if it's being written to a
Expand Down

0 comments on commit 5f73713

Please sign in to comment.