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

Re: [MacPerl] Still looking for examples



At 12.28 1998.03.13, nghai wrote:
>I'm still trying to find examples that would help me with the use of
>Mac::Menus and Mac::Events particularly for the following:
>
>  Mac::Menus - To create a custom menubar where items will invoke Perl
>subroutines

In :MacPerl Ä:ext:Mac:Menus:t: there is a nice example.

>  Mac::Events - To check if a modifier key (ctrl/cmd/opt/shift) is
>currently being depressed.

OK.  Set an event handler for your window:

  $win->sethook('key', \&handle_keys);

Then your handle_keys sub:

  sub handle_keys {
    my($my, $v) = @_;
    my($mod) = $Mac::Events::CurrentEvent->modifiers();
    if ($v == 119 && ($mod & cmdKey()) eq cmdKey()) {
      $my->dispose();
    }
  }

Now, I suck at bitmask stuff (darn liberal arts education), so someone
PLEASE tell me if I got the ($mod & cmdKey()) part right or wrong.  But it
seems to work, so what of it?  :)

Anyway, this checks if cmd-w is pressed, at the moment that "w" is actually
pressed.  If it is, it closes the window.

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==               New Book:  MacPerl: Power and Ease               ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch