Jump to content
  • Advertisement
Sign in to follow this  

Sending key strokes to a console window

This topic is 5038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So here's my problem. This is WindowsXP. I have a console command line program that I want to send commands to from another program. The console program is running in it's own window and I don't need to fetch output back from it, only feed data in. I'm aware that normally one would use pipes to redirect stdin/stdout, but because of how the console program works (something to do with not fflushing stdout when it uses printf/scanf?), this hasn't been working. So what I would really like to do is, given the command line program's HWND, I'd like to send it key presses, so it looks to the program like someone is typing in the window. Is this even possible? If so, is it possible to do without focus being shifted to the console window? What I'm actually working on: I'm using the chess engine Crafty to analyze chess positions. Given a position, it continually searches for the best move, spewing lines of analysis. I want to be able to pipe moves to Crafty for analysis from a variety of sources (the internet, chess articles, other chess programs, ect ect). I don't want to implement a full-blown ICS interface to Crafty, I'd rather just pipe commands to it. Crafty already displays such analysis quite nicely in the console window, so I only need to pipe commands into it, not read data out. I have tried using the System.Dianostics.Process object in .Net to start Crafty, redirecting only stdin - but this causes stdout to not go to the console window (this seems to be a bug). I have also been messing with some straight Win32 C++ I found online to redirect stdin/stdout in various ways, but none of them work well with crafty, so I'm convinced something about how crafty handles input/output prevents piping. Thus I need a hack.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!