[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Key handling



I'm have a window with TextEdit boxes open, and I want to handle *some* keys,
and pass the rest on.  Looking in the archive, it appears the suggested
behavior, having the key handling routine return 0 or undef to indicate a key
wasn't handled is broken (see Emails by Alan Fry, Re: [MacPerl] key event
handler in dialogs).

By commenting out the line in Hooks.pm that ignores undef returns I can
correct this behavior.

in Hooks.pm:
-----------------
sub callhook {
	my($my)   = shift @_;
	my($hook) = shift @_;
	if ($hook = $my->{$hook}) {
		$hook = &$hook(@_);
#		$hook = "Sort of defined" unless defined ($hook); #eliminated
	}
	$hook;
}
-----------------

Here's my key handling routine, which works now that Hooks.pm is changed:
-----------------
sub MAC_KEYS {

my ($win, $key) = @_;
$key1=$key;
$key = lc chr $key;
my $mod = $Mac::Events::CurrentEvent->modifiers();

if ($key eq "\c[") {$cancel=1;}		#Esc
if ($key eq "\n") {$OK=1;} 		#return
if (($key eq "w") && (($mod & cmdKey) == cmdKey)) {$cancel=1;}	#Apple-W 

return undef;
}
-----------------

I wonder about the *other* effects this change in Hooks.pm may have.  The
first one I noticed is that:

$win->sethook(drawgrowicon => sub {}); # eliminate fake grow box

no longer works, you need give the subroutine a body, like so:

$win->sethook(drawgrowicon => sub {1}); # eliminate fake grow box

So is there a better way to fix the key handler, and if not, what other
consequences will the change in Hooks.pm have?

Thanks,

Jim Lund
jsl21053@welch.jhu.edu, jiml@faith.med.jhmi.edu




===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org