Keys can be a problem because of autorepeat, but here's one that uses the left mouse button for the keyer.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11112751 use warnings; use Time::HiRes qw( time ); use Tk; my $morse = ''; my $text = ''; my $down = 0; my $lasttime = time; my $interval = shift // 0.1; # seconds for timing my $maxlength = 30; my $mw = new MainWindow; $mw->geometry('+500+500'); $mw->Label(-text => "Use left mouse button in green window.\n" . "Tweek \$interval to your coding speed")->pack; my $t = $mw->Label(-textvariable => \$morse, -width => $maxlength, -bg => 'lightgreen', -font => 'courierbold 36', )->pack; $mw->Label(-textvariable => \$text, -width => $maxlength, -font => 'courierbold 36', )->pack; $mw->Button(-text => 'Clear', -command => sub { $morse = $text = '' }, )->pack; $mw->Button(-text => 'Exit', -command => sub {$mw->destroy})->pack; $t->bind('<1>' => \&press ); $t->bind('<ButtonRelease-1>' => \&release ); MainLoop; sub morse { $_[0] =~ tr/.-/01/r =~ s/\S+/ my $pos = oct 'b1' . $&; $pos > 30 and $pos = 30; substr '__etianmsurwdkgohvf_l_pjbxcyzq?', $pos, 1 /ger =~ s/ *\K //gr; } sub press { if( time > $lasttime + 6 * $interval ) { $morse .= ' '; } elsif( time > $lasttime + 2 * $interval ) { $morse .= ' '; } length $morse > $maxlength and substr $morse, 0, length($morse) - $maxlength, ''; $lasttime = time; } sub release { if( time < $lasttime + 2 * $interval ) { $morse .= '.'; } else { $morse .= '-'; } length $morse > $maxlength and substr $morse, 0, length($morse) - $maxlength, ''; $text = morse($morse); $lasttime = time; }

In reply to Re: Morse input from keyboard by tybalt89
in thread Morse input from keyboard by pierrot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.