Sign in to follow this  

Sending key strokes to a console window

This topic is 4734 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

This topic is 4734 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.

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