Last active
February 19, 2018 16:13
-
-
Save trytone/30977fd924bdb741ff3e14e8b728aec9 to your computer and use it in GitHub Desktop.
Perl Tk - Simple touch keyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub keyboard{ | |
# init by : keyboard(\$mw->Frame()->pack(-side => 'bottom', -anchor => 'se')); | |
my $ref = shift; | |
my @numbersArray = ([(7..9)],[(4..6)],[(1..3)]); | |
my $keyboardFont = $$ref->Font(-size => 18); | |
my $keyboardFrame = $$ref->Frame(-padx => 10, -pady => 10)->pack( -fill => 'y', -expand => 1); | |
my $keyboardLeft = $keyboardFrame->Frame()->pack(-side => 'left'); | |
my $keyboardRight = $keyboardFrame->Frame->pack(-side => 'right', -anchor => 'ne', -fill => 'both', -expand => 1); | |
# Left column | |
foreach my $numbers (@numbersArray){ | |
my $line = $keyboardLeft->Frame->pack(-fill => 'x'); | |
foreach (@{$numbers}){ | |
$line->Button(-text => $_, -relief => 'groove', -pady => 6, -padx => 8, -font => $keyboardFont, -command => [\&keyInt, $_])->pack(-side => 'left', -anchor => 'nw'); | |
} | |
} | |
my $lineZero = $keyboardLeft->Frame->pack(-fill => 'x'); | |
$lineZero->Button(-text => '0', -relief => 'groove', -font => $keyboardFont, -command => [\&keyInt, '0'])->pack(-side => 'top', -anchor => 'nw', -fill => 'x', -expand => 1); | |
# Right column | |
$keyboardRight->Button(-text => "\x{2190}", -relief => 'groove', -font => $keyboardFont, -command => [\&keyInt, "BackSpace"])->pack(-side => 'top', -anchor => 'n', -fill => 'x'); | |
$keyboardRight->Button(-text => "TAB", -relief => 'groove', -font => $keyboardFont, -command => [\&keyInt, "Tab"])->pack(-side => 'top', -anchor => 'n', -fill => 'x'); | |
$keyboardRight->Button(-text => "\x{21b5}", -relief => 'groove', -font => $keyboardFont, -command => [\&keyInt, "Return"])->pack(-side => 'top', -anchor => 'n', -fill => 'both', -expand => 1); | |
} | |
sub keyInt{ | |
my $key = shift; | |
$inputEAN->eventGenerate('<KeyPress>', -keysym => $key); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment