f



catch key stroke before displaying in an entry #3

Hello

Thanks for your tips. Here is my implementation of a barcode reader.

# global variables
my $BarCodeStart = 0;
my $BarCodeEnd = 0;
my $BarCode;
my $EntryLength;

$mw->bind("<KeyPress>", [ \&KeyPressed, Tk::Ev('K') ]);

# Barcode format: degree <BARCODE> Return Control_L j

sub KeyPressed {
		my $char = $_[1];
     my ($widget) = @_;

		# End of Barcode
		if ($char eq "j" && $BarCodeStart == 1 && $BarCodeEnd == 1) {
			#Check if a Entry has the focus, if so, delete barcode
			if ($widget->isa('Tk::Entry')) {
				$widget->delete($EntryLength, length($widget->get));
			}
			$BarCodeStart = 0;
			$BarCodeEnd = 0;
			#Put Barcode in Barcode Entry
			$eBarcode->delete(0, length($eBarcode->get));
			$eBarcode->insert(0, $BarCode);
		}

		# Start of Barcode
		if ($char eq "degree" && $BarCodeStart == 0) {
			#Check if a Entry has the focus, if so, remember start of string
			if ($widget->isa('Tk::Entry')) {
				$EntryLength = length($widget->get) - 1;
			}
			$BarCodeStart = 1;
			$BarCodeEnd = 0;
			$BarCode = "";
		}

		# Read Barcode
		if ($BarCodeStart == 1) {
			if ($char eq "degree") {$char = ""}
			if ($char eq "Shift_L") {$char = ""}
			if ($char eq "Return") {$char = ""; $BarCodeEnd = 1;}
			if ($char eq "Control_L") {$char = ""}
			if ($char eq "j") {$char = ""}
			$BarCode = $BarCode . $char;
		}
}

Regards, Thomas
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu
0
Thomas
10/10/2004 10:46:17 AM
comp.lang.perl.tk 4721 articles. 0 followers. pharrendorf (19) is leader. Post Follow

0 Replies
426 Views

Similar Articles

[PageSpeed] 54

Reply: