Sign in to follow this  
v0dKA

Sleep() Question - previously about key input

Recommended Posts

I want to run my program in the background and be able to have it perform a certain action when a certain key combination is pressed - regardless of which window is currently active. What can I use to accomplish this? Also, is it possible to create this in a console application, without the formal message loop of a Windows program? [Edited by - v0dKA on March 13, 2006 6:53:51 PM]

Share this post


Link to post
Share on other sites
Thanks, I should have really thought of trying that =)

Instead of making a new thread, allow me to ask an unrelated question here.

I plan to have an infinite loop in my program to catch the aforementioned key combination. However, I don't want it to hog up all the resources. Currently, when I run it, it takes up around 50% of the CPU (I have hyperthreading on this machine). The program hardly needs that much processing power. I believe the solution to this would be to add a Sleep( 0 ) inside the infinite loop, no? I tried that, but the memory usage seems to be unaffected... Why not? Should I be concerned about having my little (less than 1MB) program take so much processing power?

Share this post


Link to post
Share on other sites
If you pass zero to Sleep the function gives up whatever time it's got left to another thread. If such a thread isn't present, Sleep(0) returns instantly...

Instead, use Sleep(1) or anything greater...

Share this post


Link to post
Share on other sites
Another quick question for which an entire thread is probably not necessary:

How can I determine if a given HWND (call it hWnd) is currently active?

Share this post


Link to post
Share on other sites
If you want to check whether or not a certain window is on the top of the Z-Order, you can call GetForegroundWindow().

[Edited by - raz0r on March 13, 2006 7:27:34 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this