Hello to everybody!

I'v got the following problem. I want the Up,Down,Tab and ShiftTab keys 
work in tables as usual. It means Tab changes only columns to right on so 
on. The working example is enclosed. 
ONE THING bother me; when I press Tab key a sound from computer is sending 
as it was error. This sound is not emited when I press Up and Down keys.

How to manage? Could anyone help me?

Waldemar Biernacki

========================================

#!/usr/bin/perl -w

use strict;

use Win32::GUI;

my $mw = new Win32::GUI::Window(
        -name   => "Main",
        -width  => 900,
        -height => 400,
#       -tabstop=>1,
);
#$mw->DialogUI( 1 );

my @edit = ();
my $dimX = 4;
my $dimY = 4;

for ( my $i = 0; $i < $dimY; $i++ ) {
        for ( my $j = 0; $j < $dimX; $j++ ) {
                $edit[$i][$j] = $mw->AddTextfield (
                        -text => $i.'x'.$j,
                        -name           => 'edit'.$i.$j,
                        -left           =>  50 + 100*$j,
                        -top            =>  50 +  20*$i,
                        -width          =>  99,
                        -height         =>  20,
#                       -tabstop    =>   1,
#                       -dialogui => 1,
                );

                eval ('sub edit'.$i.$j.'_KeyDown { what_to_do( '.$i.','.$j.' ) 
}');
        }
}

sub what_to_do {
        my ( $i, $j ) = ( shift, shift );

        my $hash_EVENT = Win32::GUI::GetKeyboardState;
        my $_EVENT     = what_event( $hash_EVENT );

        my $nextX = $j + 1; $nextX = 0 if $nextX >= $dimX;
        my $prevX = $j - 1; $prevX = $dimX-1 if $prevX < 0;
        my $nextY = $i + 1; $nextY = $dimY-1 if $nextY >= $dimY;
        my $prevY = $i - 1; $prevY = 0 if $prevY < 0;

        if ( $_EVENT eq 'Tab'      ) { $edit[$i][$nextX]->SetFocus() }
        if ( $_EVENT eq 'ShiftTab' ) { $edit[$i][$prevX]->SetFocus() }
        if ( $_EVENT eq 'Up'       ) { $edit[$prevY][$j]->SetFocus() }
        if ( $_EVENT eq 'Down'     ) { $edit[$nextY][$j]->SetFocus() }
}

$edit[0][0]->SetFocus();

$mw->Show();

Win32::GUI::Dialog();

sub Main_Terminate { -1; }

sub what_event {
        my $_EVENT = shift;
        my $result = '';
        my $SHIFT  = '';

        if (( $_EVENT->[160] )||( $_EVENT->[161] )) { $SHIFT = 'Shift' }

        for ( my $i = 0; $i < 256; $i++ ) {
                if ( $_EVENT->[$i] ) {
                        if    ( $i ==  9 ) { $result = $SHIFT.'Tab' }
                        elsif ( $i == 38 ) { $result = $SHIFT.'Up'  }
                        elsif ( $i == 40 ) { $result = $SHIFT.'Down'}
                }
    }

        return $result;
}

__END__


Attachment: exam.pl
Description: Binary data

Reply via email to