catching ctrl chars

Discussion in 'Perl Misc' started by justme, Jun 30, 2004.

  1. justme

    justme Guest

    hi

    how can i catch Ctrl-x (or any other letters except 'c' ) in perl ??
    thanks..
     
    justme, Jun 30, 2004
    #1
    1. Advertising

  2. justme

    John Bokma Guest

    John Bokma, Jun 30, 2004
    #2
    1. Advertising

  3. Sherm Pendley, Jun 30, 2004
    #3
  4. justme

    justme Guest

    Abigail <> wrote in message news:<>...
    > justme () wrote on MMMCMLVI September MCMXCIII in
    > <URL:news:>:
    > <> 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?
     
    justme, Jul 1, 2004
    #4
  5. justme

    Keith Keller Guest

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

    On 2004-07-01, justme <> wrote:

    > 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

    - --
    -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-----
     
    Keith Keller, Jul 1, 2004
    #5
  6. justme

    justme Guest

    Keith Keller <-francisco.ca.us> wrote in message news:<-francisco.ca.us>...
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > On 2004-07-01, justme <> wrote:
    >
    > > 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
    >
    > - --
    > -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
     
    justme, Jul 2, 2004
    #6
  7. justme

    Paul Lalli Guest

    On Fri, 2 Jul 2004, justme wrote:

    > 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
     
    Paul Lalli, Jul 2, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny

    Implement Ctrl-C, Ctrl-V

    Danny, Aug 14, 2003, in forum: C++
    Replies:
    5
    Views:
    653
    CBFalconer
    Aug 15, 2003
  2. Danny

    Implement Ctrl-C, Ctrl-V

    Danny, Aug 14, 2003, in forum: C Programming
    Replies:
    5
    Views:
    668
    CBFalconer
    Aug 15, 2003
  3. Angus
    Replies:
    5
    Views:
    2,120
    Michael Rauscher
    Nov 18, 2006
  4. Replies:
    2
    Views:
    1,422
    Munna
    Jul 10, 2008
  5. Replies:
    0
    Views:
    562
Loading...

Share This Page