问题
Let's say I was using cin
in my program to allow the user to input into the console. That is simple enough but what if they were typing into, let's say, a web browser and I wanted them to input that into the console at the same time? When I click away the C++ program console window and have something else on top, the input obviously does not go into the console. How can I make it so the console is always running on top so that even when I were to input something into a web browser, it would also go into the console?
回答1:
in order capture keyboard input when your application is not focused, you need to use windows hook, see:
http://msdn.microsoft.com/en-us/library/ms644959%28v=vs.85%29.aspx#wh_keyboardhook
Example code can be found here:
http://www.codeguru.com/cpp/w-p/system/keyboard/article.php/c5699/Hooking-the-Keyboard.htm
回答2:
I think you may want to take a look at hooking the keyboard to get the input?
来源:https://stackoverflow.com/questions/19212527/keep-a-running-c-program-console-on-top