catching ctrl chars

J

justme

Abigail said:
justme ([email protected]) wrote on MMMCMLVI September MCMXCIII in
<URL:<> hi
<>
<> how can i catch Ctrl-x (or any other letters except 'c' ) in perl ??
<> thanks..


What do you mean by "catching" ctrl-x? Matching with a regex?


Abigail

hi

i want to catch from the keyboard. I have looked at perldoc -q signal

$Interrupted = 0; # to ensure it has a value
$SIG{INT} = sub {
$Interrupted++;
syswrite(STDERR, "ouch\n", 5);
}

Does this example catch Ctrl-x?
 
K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

i want to catch from the keyboard. I have looked at perldoc -q signal

perldoc -q signal talks about trapping signals, not catching keystrokes.
$Interrupted = 0; # to ensure it has a value
$SIG{INT} = sub {
$Interrupted++;
syswrite(STDERR, "ouch\n", 5);
}

Does this example catch Ctrl-x?

No, it traps SIGINT, which is commonly sent by ctrl-c. IIRC ctrl-x
doesn't normally send a signal, so you can't trap it this way.

Why don't you describe your goal, rather than trying to describe what
you think you want to do? Why are you so concerned with ctrl-x?

- --keith

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFA44FhhVcNCxZ5ID8RAgSfAJwOszJpruEcvk6lD6kgMqSVhWotjwCgjq6C
Ro02Dl1lGYWpTt+NrFDzCAE=
=EM95
-----END PGP SIGNATURE-----
 
J

justme

Keith Keller said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



perldoc -q signal talks about trapping signals, not catching keystrokes.


No, it traps SIGINT, which is commonly sent by ctrl-c. IIRC ctrl-x
doesn't normally send a signal, so you can't trap it this way.

Why don't you describe your goal, rather than trying to describe what
you think you want to do? Why are you so concerned with ctrl-x?

- --keith

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFA44FhhVcNCxZ5ID8RAgSfAJwOszJpruEcvk6lD6kgMqSVhWotjwCgjq6C
Ro02Dl1lGYWpTt+NrFDzCAE=
=EM95
-----END PGP SIGNATURE-----


actually this is what i want:

A user interface to prompt user to continue or use ctrl-x to return to
previous menu.


eg

"Do you accept? [Yn] or Ctrl-x to return to previous"

When the user press Ctrl-x, it will go back to previous page...

something like that....
thanks
 
P

Paul Lalli

actually this is what i want:

A user interface to prompt user to continue or use ctrl-x to return to
previous menu.


eg

"Do you accept? [Yn] or Ctrl-x to return to previous"

When the user press Ctrl-x, it will go back to previous page...

CTRL-X has a ordinal representation of 24. (At least it does for me on
the two systems I tried it out - WinXP and Solaris). Here is a solution
based on the documentation previously suggested to you
perldoc -q single


#!/usr/bin/perl
use strict;
use warnings;
use Term::ReadKey;

print "Do you accept? [Yn] or Ctrl-x to return to previous\n";
ReadMode "raw";
my $key = ReadKey 0, *STDIN;
if (ord($key) == 24) {
previousPage;
} elsif ($key =~ /^y$/i){
heSaidYes;
} else {
heSaidNo;
}


Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top