Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

using perl to "press enter"

by Anonymous Monk
on Dec 05, 2012 at 18:35 UTC ( #1007362=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am not sure this is possible, but I want to somehow write to stdio or some such and make a perl script that will press enter on a timer. This is for a windows application that I have to mindlessly babysit. (and that I can't launch as a child process) This is what I am using currently to tell me when to hit enter....

while (true) { print"\n$t" $t=$t-1 sleep(1); if($t<0) { print "press enter NOW"; #TODo - hit enter automagically $t = $timerlength; #reset } }

Comment on using perl to "press enter"
Download Code
Re: using perl to "press enter"
by space_monk (Chaplain) on Dec 05, 2012 at 18:40 UTC

    It sounds to me as though you really want an automated test application, or to create one in Perl. I bumped into Win32::GuiTest which seems to do the sort of thing you want. i.e. send keystrokes to a Windows application.

    A Monk aims to give answers to those who have none, and to learn from those who know more.
Re: using perl to "press enter"
by Not_a_Number (Parson) on Dec 05, 2012 at 20:33 UTC

    This seems to work for me:

    use strict; use warnings; use Win32::Console; my $console = Win32::Console->new( STD_OUTPUT_HANDLE ); my $timerlength = 5; # or whatever while ( 1 ) { sleep $timerlength; $console->Write( "\n" ); }

    If you have ActiveState perl, Win32::Console is packaged with it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007362]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-09-16 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (45 votes), past polls