GiacomoLaw / Keylogger

A simple keylogger for Windows, Linux and Mac
https://simple-keylogger.github.io/
MIT License
2.09k stars 616 forks source link

Windows: while(1) #17

Closed ehrlich-b closed 7 years ago

ehrlich-b commented 7 years ago

There's no reason this should be using an entire CPU constantly.

Naive solution: Poll every millisecond rather than constantly. It's not going to be possible for someone to press/release a key in under a millisecond, so you won't miss anything. This should make it go from 100% of one CPU to 0%. An average machine is probably running the code inside that tight loop millions of times per second - if you cap it at 1000 times per second you will be saving 99.9% of the CPU time.

"Correct" solution: You can register your program to be notified on key events globally. https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx so you don't have to poll at all.

GiacomoLaw commented 7 years ago

Thanks for the answer! As usual, feel free to fork and submit a pull request. I currently don't have time (and the experience) to do this.

But as usual, your pull requests and comments are appreciated! 😄