Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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 } }

Replies are listed 'Best First'.
Re: using perl to "press enter"
by Not_a_Number (Prior) 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.

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007362]
Approved by davido
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-11-22 08:34 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (316 votes). Check out past polls.