The script below works on MacPerl 5.6.1b2 (not on 5.2.0r4 because it uses
Time::HiRes). It repeatedly sings the name of the key while it is being
depressed using the melody supplied with the cello voice. The exception is
the "u" key which repeats a monotone "u".

If I change the following line from the keyDown_Handler sub
   $speech = "$k " x 200;
to
   $speech = "$k" x 200;
it works like the other letter and number keys do.

Any idea why the "u" key acts uniquely? Just curious.

David Seay
http://www.mastercall.com/g-s/


-----------

#!perl

use Mac::Events;
use Mac::Events qw(@Event $CurrentEvent);
use Mac::LowMem;
use Mac::Speech;
use Time::HiRes qw(gettimeofday);

  $Event[keyDown] = \&keyDown_Handler;
  $Event[keyUp]   = \&keyUp_Handler;
  LMSetSysEvtMask(LMGetSysEvtMask() | keyUpMask);
  $voice = $Voice{Cellos};
  print "Hold down a number or letter key... (Press cmd \".\" to quit)\n\n";

  while (! $flag) {
     if ($keyStatus eq "down" && ! SpeechBusy()) { SpeakText $channel,
$speech or die $^E }
     if ($keyStatus eq "up" && $channel) { DisposeSpeechChannel $channel }
     WaitNextEvent;
  }

  if ($channel) { DisposeSpeechChannel $channel }
  print "\n\nDONE!\n";
exit;


sub keyDown_Handler {
    ($startSeconds, $startMicroseconds) = gettimeofday;
    my($ev) = @_;
    $k = chr($ev->character);
    if (($CurrentEvent->modifiers & 256) == 256 && ($k eq "." || $k eq
"q")) { $flag = 1 }
    else { print "KEY DOWN = $k\n" }
    if ($channel) { DisposeSpeechChannel $channel }
    $channel = NewSpeechChannel($voice) or die $^E;
    $speech = "$k " x 200;
    $keyStatus = "down";
}

sub keyUp_Handler {
    ($seconds, $microseconds) = gettimeofday;
    $start = $startSeconds * 1000000 + $startMicroseconds;
    $end = $seconds * 1000000 + $microseconds;
    $dif = $end - $start;
    $difSec = int($dif / 1000000);
    $difMicroSec = $dif % 1000000;
    print "\b for $difSec.$difMicroSec seconds\n\n";
    $keyStatus = "up";
}

__END__





Reply via email to