Hello!

Maybe you could me help?

I have the code (read later please). What is my problem?
The aim of the program is to catch keyboard events and write them into string 
named $_EVENT. However it works different in WindowsXP (correctly I think) 
and in Windows98 (wrong). It can be seen in console printouts on the both 
systems.

In windows 98 I notice the application with this "catching" stops with errors 
which point to Dialog function. In Windows XP everything is allright.

cheers
Waldemar

===============================================================================================
#!/usr/bin/perl -w

use strict;
use Win32::GUI qw();

my $_EVENT  = '';

my $Window = new Win32::GUI::Window (
        -name  => "Window",
        -pos   => [0,0],
        -size  => [200,100],
        -onResize => sub {
                my ($self) = @_;
                my ($width,$height) = ($self->GetClientRect())[2..3];
                $self->Pole->Resize($width+1, $height+1) if exists 
$self->{Pole};},
        -onKeyDown   => \&keydown,
    -onTerminate => sub { return -1 },
);


$Window->AddTextfield(
        -name          => "Pole",
        -pos           => [0,0],
        -size          => [800,600],
        -onKeyDown   => \&keydown,
);

$Window->Pole->Text("");
$Window->Pole->Append("Exit = Alt+F4");
$Window->Pole->SetFocus();

$Window->Show();


Win32::GUI::Dialog();

##########################################################################

#---------------------------------------------

sub keydown {
        my ( $self, undef, $key ) = @_;

        my $hash_EVENT = Win32::GUI::GetKeyboardState;

        $_EVENT = what_event( $hash_EVENT );

        print $_EVENT,"|\n";

        return 1;
}

#---------------------------------------------

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

        if (( $_EVENT->[160] )||( $_EVENT->[161] )) { $SHIFT = 'Shift' }
        if (( $_EVENT->[162] )||( $_EVENT->[163] )) { $CTRL  = 'Ctrl'  }
        if (( $_EVENT->[164] )||( $_EVENT->[165] )) { $ALT   = 'Alt'   }

        if (( $_EVENT->[16] )) { $SHIFT = 'Shift' }
        if (( $_EVENT->[17] )) { $CTRL  = 'Ctrl'  }
        if (( $_EVENT->[18] )) { $ALT   = 'Alt'   }

        for ( my $i = 0; $i < 256; $i++ ) {
                if ( $_EVENT->[$i] ) {
print $i,'|';
                        if ( $i == 0 ) { $result .= 'Null' }
                        elsif ( $i ==  8 ) { $result = 'Backspace' }
                        elsif ( $i ==  9 ) { $result = $CTRL.$SHIFT.'Tab' }
                        elsif ( $i == 13 ) { $result = $CTRL.$SHIFT.'Enter'  }
                        elsif ( $i == 27 ) { $result = $CTRL.$SHIFT.'Escape' }
                        elsif ( $i == 33 ) { $result = $CTRL.$SHIFT.'PgUp'   }
                        elsif ( $i == 34 ) { $result = $CTRL.$SHIFT.'PgDn'   }
                        elsif ( $i == 36 ) { $result = $CTRL.$SHIFT.'Home'   }
                        elsif ( $i == 35 ) { $result = $CTRL.$SHIFT.'End'    }
                        elsif ( $i == 38 ) { $result = $CTRL.$SHIFT.'Up'     }
                        elsif ( $i == 37 ) { $result = $CTRL.$SHIFT.'Left'   }
                        elsif ( $i == 39 ) { $result = $CTRL.$SHIFT.'Right'  }
                        elsif ( $i == 40 ) { $result = $CTRL.$SHIFT.'Down'   }
                        elsif ( $i == 45 ) { $result = $CTRL.$SHIFT.'Insert' }
                        elsif ( $i == 46 ) { $result = $CTRL.$SHIFT.'Delete' }
                        elsif (( 47 < $i )&&( $i < 58 )) { $result = 
$CTRL.$SHIFT.chr( $i ) }
                        elsif (( 64 < $i )&&( $i < 91 )) {
                                my $shift = 0; $shift = 32 if (( $SHIFT eq 
'Shift' )||( $CTRL 
eq 'Ctrl' ));
                                $result = $CTRL.$ALT.chr( $i + 32 - $shift ) }
                        elsif (( 111 < $i )&&( $i < 124 )) {
                                $result = $ALT.$CTRL.$SHIFT.'F'.($i-111); }
                        else {
                                if (( $i != 160 )&&( $i != 161 )&&( $i != 16 )&&
                                        ( $i != 162 )&&( $i != 163 )&&( $i != 
17 )&&
                                        ( $i != 164 )&&( $i != 165 )&&( $i != 
18 )) {
                                        }
            }
                }
        }

        return $result;
}
===============================================================================================

Attachment: test_kbd.pl
Description: Perl program

Reply via email to