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

Re: [MacPerl-Toolbox] forwarding events



Marion Blatter writes Fri, 09 Jul 1999 00:34:20 +0200

I see the name Jan Hoffman at the bottom, so apologies if I've got this
wrong. Anyway, thanks for your message.

>Thank you for the reply. But my intention is to change (:-) the behavior
>of some key-presses without loosing the benefit of a MacDialog.
>This evening I found the command I was looking for in the dialogs.pm:
>
>key KEY:         Handle a keypress and return 1 if the key was handled.

Yes, I understand exactly what you are aiming at. The problem is that once
you have captured the event with $Event[keyDown] it is no longer 'seen' by
Windows.pm. The difficulty is to find a way of reurning the event to
Windows at the right point. I don't think you can do what you suggest,
ingenious though it is.

>So I can use (take a look at the script below):
>
>   $Mac::Events::Event[keyDown] = \&Handler;
>
>to get all key-presses and handle the ones I want to. For the other keys
>I can force the dialog to perform its "default action" using:
>
>   $dialog->key($event->key)
>
>I used this to write the script below. There I changed the behavior of
>the cursor keys.
>So one can "browse" quickly through large edit-arrays with the cursor
>keys.
>But there is a fatal bug. The System crashes after using a copy/paste
>command.

Yes, I aagree -- it does. I'm not sure why exactly, but it maybe to do with
the fact the MenuBar also calls the key equivalents Cmd-X, C, V which don't
work either.

>I wonder if the behaviour of my script belongs to the same bug or if I
>forgot something?

I'm not sure.

>Furthermore I was surprised because I couldn't even catch the crash
>using:
>
>   unless($event->modifiers == 128) {return};
>
>in the body of my handler. I intended to return directly if any
>modifying key was pressed.

That line is incorrect -- you have to use the bit-wise '&' to test if the
'128' bit is set, like:

    unless ($event->modifiers & 128 == 128) {

>This prevents you from writing capital letters but not the system from
>crashing after
>copy & paste actions. I wonder why?

Yes -- you'll find $event->modifers probably returns something like 2176,
because there are also other flags set.

>There's also a very strange minor bug. The Handler doesn't handle the
>very first event.
>So the first written letter can be capital and if you press a curser key
>as the very first key,
>nothing happens. Can someone tell me why?

This is to do with the 'fudge' with the line '$dlg->modal'. It has the side
effect of redrawing the MenuBar (so that Cut, Copy and Paste work without
crashing) but other undesirable effects. The dialog is 'modal' for the
first event (key press or whatever) only, thereafter it becomes non-modal.
The whole thing is very unsatisfactory.

I can see what you want to do, and It's an interesting problem. I don't see
how to go about it at the moment, but I will give it some thought and come
back.

Alan Fry



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