sending keystroke to a dos application

Adrian Eyre a.eyre at optichrome.com
Mon Jan 31 08:39:28 EST 2000


> I believe that's not what he meant. He has an existing application
> (probably non-Python) that runs in a DOS box. He wants to script it
> with Python by sending keystrokes to it.

Ahhh. Completely misread that one. :)

It depends how the DOS app gets the keystrokes. If it uses the normal
method (i.e. from stdin), then you should be able to do it with
os.popen(). e.g.

# Warning: Untested code
import os

class DOSApp:

	def __init__(self, filename):
		self.progpipe = os.popen(filename)

	def __del__(self):
		self.progpipe.close()

	def sendKeyPress(self, char):
		self.progpipe.write(char)
		self.progpipe.flush()
		
myApp = DOSApp("c:\\someapp.exe")
myApp.sendKeyPress("a")
myApp.sendKeyPress("b")
myApp.sendKeyPress("c")

If it goes straight to the BIOS, it's a lot more tricky, and is
pretty much outside the scope of Python's abilities (unless you're
prepared to write an extension module to do it.)

--------------------------------------------
Adrian Eyre <a.eyre at optichrome.com>
http://www.optichrome.com 





More information about the Python-list mailing list