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.
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.