While Loop Taking Alot of CPU Usage
Posted
by CuriousUser
on Stack Overflow
See other posts from Stack Overflow
or by CuriousUser
Published on 2009-09-16T04:10:22Z
Indexed on
2010/04/19
7:23 UTC
Read the original article
Hit count: 274
I am creating a keystroke logger for my personal interest, as well wanting to know how to capture and use them as functions (like key shortcuts).
I got the code to learn how keylogger and GetAsyncKeyState() work: http://www.rohitab.com/discuss/index.php?showtopic=9931
I got it to run under Code::Blocks, but the weirdest things is that when I check my task manager, my CPU Usage rises to 100%. When I close the program, it goes back down, and goes back up to 100 when I turn it back on.
I presume it's because of the infinite while loop, constantly checking for inputs, but I wanna know if there's anyway to decrease the CPU usage, without losing function.
P.S How would I make a key shortcut? Like press (Ctrl + E) to make the program exit?
© Stack Overflow or respective owner