Hi All.

I am trying to create my own CLI navigation program. I am using Term::Screen 
since it is nice and simple. I am aware that there are other modules out there 
which does all this. But I want to learn more about the navigation of the 
cursor around the screen. Initially I am working with something that I believe 
is simple and then I will migrate to Curses. But not yet.

I have been successful in creating the menu. The menu wraps. But I cannot get 
the spacebar or enter key to be excepted. Below is the code:


#!/usr/bin/perl -w

# Mac Perl 5.12 

use strict;
require Term::Screen;

  my $scr = new Term::Screen;
  my $win_col = $scr->cols();
my $win_row = $scr->    rows();
$scr->clrscr();
$scr->at(0,0)->clreol()->puts ("window size: $win_row\t$win_col");

for (my $r = 2; $r <= $win_row; $r++) {
# prints menu.
        my $item = $r -2;
        $scr->at($r,10)->puts("$item - menu item $item");
} #end while 
my $curser_char = '_';
$scr->at(2, 0)->puts($curser_char);
$scr->noecho();
my $col = 0;
my $row = 2;
my $top_row = 2;
my $bottom_row = $win_row;

while ( 1) {
        my $key = $scr->getch();
        if ($key eq "kd") {
                $scr->at($row, $col)->puts(' ');
                ++$row;
                $row = $top_row if ($row > $bottom_row);
        } elsif ($key eq "ku") {
                $scr->at($row, $col)->puts(' ');
                --$row;
                $row = $bottom_row if ($row < $top_row);
        } else {
                last if ($key eq 'ke');
                last if ($key eq 'q');
        } #end if 
        $scr->at($row, $col)->puts("$curser_char $row -");
} # end while

so how do you capture the Enter or Space? 

I have read the code for Term::Screen and it doesn't appear to have this as one 
of the defined keys in the last routine.

Sean
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to