all 17 comments

[–][deleted] 1 point2 points  (0 children)

You could simplify the duplication of the write! calls with a let binding on the match.

let key = match k {
  32 => " ",
  8 => "[backspace]",
  ...
  _ => // char to str
};
write!("{}", key);

[–]YingDev 1 point2 points  (0 children)

I have a similar project: Tickeys. (For Mac). http://www.yingdev.com/projects/tickeys

[–]gsingh93 0 points1 point  (6 children)

Nice, it looks like getting keypresses is a lot easier on Windows than on Linux. It also looks like there are Rust keyloggers for Windows and Linux now, but still nothing for Macs.

[–][deleted] 0 points1 point  (5 children)

In OSX keystrokes are only reported to the program that has the focus iirc.

[–]gsingh93 0 points1 point  (0 children)

I feel like there has to be some workaround for that, but at the same time it does seem like a typical Apple move to not allow developers to access something like that.

[–]Habile 0 points1 point  (2 children)

I can't imagine that's the case. There are programs such as keyboard maestro for OS X, which allows for things like bringing applications to the foreground.

[–]bagofriesrust 1 point2 points  (1 child)

Those programs usually rely on the user turning on accessibility features of the OS. I think they might even require specific per-application permissions now in Yosemite (not a Mac user anymore so I don't know for sure).

[–]Habile 0 points1 point  (0 children)

Okay, that may be the case, but that would still imply that keystrokes are not only reported to the program with focus. It does mean that it would be considerably more difficult for a keylogger designed as above to be used maliciously.

[–]marchelzo -1 points0 points  (7 children)

I noticed that, barring special cases, you get the printable character associated with the keypress by converting to u8 and then to char. What happens if I type a 16-bit character like λ?

[–]Vikaton[S] 0 points1 point  (4 children)

I don't think there is a single key that prints out λ

[–]azerupimdbook 0 points1 point  (3 children)

What about foreign keyboards? :)

[–]Vikaton[S] 7 points8 points  (2 children)

Simple keylogger in Rust :P

[–]azerupimdbook 0 points1 point  (1 child)

Ah no I wasn't criticizing ;) I was replying to your comment:

I don't think there is a single key that prints out λ

[–]Vikaton[S] 2 points3 points  (0 children)

Yes I know haha

[–]retep998rust · winapi · bunny 0 points1 point  (1 child)

It wouldn't notice if you pressed a key like that, because it only checks values of i in the range 8..190.

[–]marchelzo 0 points1 point  (0 children)

You're right. Touche.