Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help typing to wordpad

JesseShowJesseShow Posts: 2Member
[b][red]This message was edited by Moderator at 2004-3-9 7:37:27[/red][/b][hr]
I have this program, realizing that I'm new to Python, that I need to type the keys (Crtl+Shift+6) and N while the term_495 application is running, but I'm not sure how to do it. These are shown in the program as l and m, so I know I can print then in the cmd.exe runs.

Basically, I'd like to open a program and then type to keystrokes from the keyboard and then close the program, say on Wordpad.

Anyone have some help on how I can do this?

Heres the program, of which most of the stuff I didnt work on.

[code]
import sys
import re
import win32api
import win32process
import win32event
x = "0"
l = "?"
m = "N"

term_app = "term_495"

s = raw_input( "Please enter the model number: " )
print s
print l
print m
t = raw_input( "Please scan the assembly label: " )
if q == t:
print "Match!"

loader = "lo400100.s "


if t == "1":
x = "1"
aterm_app = "term_495"
app = "cb420100.s -a"
warning = "warning.txt"
wterm_app = "wordpad.exe"

elif t == "226-9253":
x = "2"
loader = "lo40c150.s -a"
aterm_app = "ETECH.EXE"
app = "239927300.FLS"
warning = "warning.txt"
wterm_app = "wordpad.exe"

sn = raw_input( "Please enter the serial number: " )

print sn
if x == "1":
os.system( term_app + " " )
f = raw_input("Waiting 30 seconds for unit to repower up")
z = 1
while z < 270000:
z = z+1
print "Waiting...."
os.system( term_app + " " + loader )
os.system( wterm_app + " " + warning)
os.system( aterm_app + " " + app )
elif x == "2":
os.system( term_app + " " )
os.system( term_app + " " + loader )
os.system( wterm_app + " " + warning)
os.system( aterm_app + " " + app )

else:
term_app = "WORDPAD.EXE"
ERROR = "ERROR.TXT"
rprint(l)
rprint(m)
os.system(term_app + " " + ERROR)
else:
term_app = "WORDPAD.EXE"
ERROR = "ERROR.TXT"
os.system(term_app + " " + ERROR)
[/code]







Comments

  • infidelinfidel Posts: 2,900Member
    : [b][red]This message was edited by Moderator at 2004-3-9 7:37:27[/red][/b][hr]
    : I have this program, realizing that I'm new to Python, that I need to type the keys (Crtl+Shift+6) and N while the term_495 application is running, but I'm not sure how to do it. These are shown in the program as l and m, so I know I can print then in the cmd.exe runs.
    :
    : Basically, I'd like to open a program and then type to keystrokes from the keyboard and then close the program, say on Wordpad.

    I'm not sure Python is well suited to this kind of task, but I figure almost anything is possible if you know where to look. The Windows API has a SendMessage function which can be used to send keystrokes to a window if you know it's handle. The trick is finding the handle and knowing what parameters to send to it. I'm sure the necessary functions are in the win32api module, but I try to avoid this kind of programming so I can't really help much.

    : Anyone have some help on how I can do this?

    You'll have to find the handle of the window you want to send keystrokes to. The FindWindow API might help but I do not know for certain. The win32event module might hold some keys to your problem too.

    : [code]
    : import sys
    : import re
    : import win32api
    : import win32process
    : import win32event
    : x = "0"
    : l = "?"
    : m = "N"
    :
    : term_app = "term_495"
    :
    : s = raw_input( "Please enter the model number: " )
    : print s
    : print l
    : print m
    [/code]

    Not sure why you're printing l and m to stdout, but whatever.

    [code]
    : t = raw_input( "Please scan the assembly label: " )
    : if q == t:
    [/code]

    I don't see where q was set to anything.

    [code]
    : print "Match!"
    :
    : loader = "lo400100.s "
    :
    :
    : if t == "1":
    : x = "1"
    : aterm_app = "term_495"
    : app = "cb420100.s -a"
    : warning = "warning.txt"
    : wterm_app = "wordpad.exe"
    :
    : elif t == "226-9253":
    : x = "2"
    : loader = "lo40c150.s -a"
    : aterm_app = "ETECH.EXE"
    : app = "239927300.FLS"
    : warning = "warning.txt"
    : wterm_app = "wordpad.exe"
    :
    : sn = raw_input( "Please enter the serial number: " )
    :
    : print sn
    : if x == "1":
    : os.system( term_app + " " )
    : f = raw_input("Waiting 30 seconds for unit to repower up")
    : z = 1
    : while z < 270000:
    : z = z+1
    : print "Waiting...."
    [/code]

    You know there is a sleep function in the time module. You could also write this loop more efficiently as:

    for x in xrange(270000): print "Waiting...."

    Assuming you really want to print your message 270,000 times.

    [code]
    : os.system( term_app + " " + loader )
    : os.system( wterm_app + " " + warning)
    : os.system( aterm_app + " " + app )
    : elif x == "2":
    : os.system( term_app + " " )
    : os.system( term_app + " " + loader )
    : os.system( wterm_app + " " + warning)
    : os.system( aterm_app + " " + app )
    :
    : else:
    : term_app = "WORDPAD.EXE"
    : ERROR = "ERROR.TXT"
    : rprint(l)
    : rprint(m)
    : os.system(term_app + " " + ERROR)
    : else:
    : term_app = "WORDPAD.EXE"
    : ERROR = "ERROR.TXT"
    : os.system(term_app + " " + ERROR)
    : [/code]




    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.