Skip to content

Instantly share code, notes, and snippets.

@MattBlissett
Created February 16, 2013 13:41
Show Gist options
  • Save MattBlissett/4966981 to your computer and use it in GitHub Desktop.
Save MattBlissett/4966981 to your computer and use it in GitHub Desktop.
Analysing keyboard layouts Prints out stdin in the manner of the scan on http://infohost.nmt.edu/~shipman/ergo/parkinson.html Summarises transitions between left and right hand
#!/usr/bin/perl
#
# Prints out stdin in the manner of the scan on http://infohost.nmt.edu/~shipman/ergo/parkinson.html
# Summarises transitions between left and right hand
#
$input = `cat`;
# Qwerty
$l = "`¬1!2\"3£4\$5%6^qQwWeErRtTaAsSdDfFgG\\|zZxXcCvVbB";
$r = "7&8*9(0)-_=+yYuUiIoOpP[{]}hHjJkKlL;:'@#~nNmM,<.>/?";
print STDERR "Qwerty: ";
count_transitions($l, $r, $input);
# Colemak
$l = "`¬1!2\"3£4\$5%6^qQwWfFpPgGaArRsStTdD\\|zZxXcCvVbB";
$r = "7&8*9(0)-_=+jJlLuUyY;:[{]}hHnNeEiIoOuU#~kKmM,<.>/?";
print STDERR "Colemak: ";
count_transitions($l, $r, $input);
# Dvorak
$l = "`¬1!2\"3£4\$5%6^@',<.>pPyYaAoOeEuUiI\\|;:qQjJkKxX";
$r = "7&8*9(0)[{]}fFgGcCrRlL/?=+dDhHtTnNsS-_#~bBmMwWvVzZ";
print STDERR "Dvorak: ";
count_transitions($l, $r, $input);
sub count_transitions {
my ($l, $r, $input) = @_;
@lhs = split(//, $l);
@rhs = split(//, $r);
$transitions = 0;
$left = 0;
$i = 0;
foreach (split //, $input) {
foreach $x (split (//, $_)) {
if ( $x ~~ @lhs) {
print "\e[7m$x\e[m";
$transitions++ unless $left;
$left = 1;
}
elsif ($x ~~ @rhs) {
print "$x";
$transitions++ if $left;
$left = 0;
}
else {
print $x;
}
$i++;
print "$i\n" unless ($i % 1000000);
}
}
print STDERR "$transitions transitions\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment