Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Press any key to continue..."

Status
Not open for further replies.

1yura1

Programmer
Feb 7, 2003
36
UA
How can I make in perl script such procedure where script is waiting for pressing a key. "Press any key to continue..."
 
...and of course you can do it in a gui environment via perl Tk

svar
 
So far I have this for "press any key" - I'm thinking there's a better way but this actually works with "ANY KEY" insted of the ENTER key and anything prior to it.

The Win32::Console is part of perl now I think so you don't have to do any install.

Hope it helps, I'm always hunting for a better 'any key' ;)


use Win32::Console;
my $StdIn = new Win32::Console( STD_INPUT_HANDLE );
my $Password = "";
$StdIn->Mode( ENABLE_PROCESSED_INPUT );
print "Press Any Key\n";

while ( my $Data = $StdIn->InputChar( 1 ) ) {
print "$Data\n";
if ($Data ne "") {
last;
}
}
 
I don't know if this is really considered good programming practice, but in Windows, you can always use:

system(pause);
 
Another alternative is to download the Term module from CPAN and use a ReadMode/ReadKey combination.
Code:
#!usr/bin/perl -w

use strict;
use Term::ReadKey;

sub pause();

print "Test\n";
pause;

sub pause() {
    print "Press any key to continue...";

    ReadMode 'cbreak';
    ReadKey(0);
    ReadMode 'normal';
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top