Checking for input

Started by
1 comment, last by Madgap 19 years, 11 months ago
I''m running a server as a console app, but I would like to allow player to input commands while the server is running. I''ve searched online but can''t seem to find what I''m looking for. I want to check for user input without pausing my main loop. If there is no input the loop should keep on going, so I can''t use: cin >> input; Any simple way to do this with standard input?
-Madgap
Advertisement
You''ll have to get the state of keyboard each frame asynchronously, and then evaluate which keys have been pressed/released in order to determine a sequence of user input. Calling the GetKeyboardState function initially will get the state of all the keys. Once you find a key that''s pressed, add it to your persistent input buffer, and call GetAsyncKeyState on that key in particular until you find it''s released. During this time, you can choose to repeat the character ala traditional input fashion, or just ignore it (the latter is probably an easier solution). Once the key is released, call GetKeyboardState again, and repeat. If you find that the return key is pressed, then you can pass the collected input to the parsing system, clear the buffer, and continue.

There''s a lot of input functionality that you aren''t replicating, such as the ability to press a second key while the first one is still down, pressing multiple keys at once, repeating the key if it''s held down, etc., but keeping it simple is a good place to start.
Thanks, that''s just what I need.
-Madgap

This topic is closed to new replies.

Advertisement