Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Tk Virtual Keyboard

by zentara (Archbishop)
on Feb 26, 2008 at 20:34 UTC ( #670386=snippet: print w/replies, xml ) Need Help??
Description: This mimics the javascript virtual keyboards, which are commonly being used by online banks, to avoid keystroke loggers, when entering passwords. It's just the basic model. I still need to run tests on it to see if the letters and passwords can be kept more hidden. But if you ever wanted to play with something like this, but didn't want to go thru all the hassle of building the keyboard...... here is one for you.

The big font I use, makes the script take significantly longer to start up, but is worth it for ease of letter reading.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

# an 8 x 13 grid
my @keys = (
'~','`','!','@','#','$','%','^','&','*','(',')','_',    
'1','2','3','4','5','6','7','8','9','0','-','+','=',  
'Q','W','E','R','T','Y','U','I','O','P','{','}','"', 
'q','w','e','r','t','y','u','i','o','p','[',']','\'',
'A','S','D','F','G','H','J','K','L',':','|','\\','/',
'a','s','d','f','g','h','j','k','l',';','<','>','?', 
'Z','X','C','V','B','N','M','BackSpace','dummy','dummy','dummy','dummy
+','dummy',
'z','x','c','v','b','n','m','.','Clear','dummy','dummy','dummy','dummy
+');

#print "@keys\n";

my $mw=tkinit;

$mw->fontCreate('big',
   -family=>'arial',
  -weight=>'bold',
  -size=>int(-18*18/14));

 my $tframe = $mw->Frame()->pack(-expand=>1,-fill=>'both');   
 my $passwd = '';
 my $label = $tframe->Label(-text => "Password: ",
                            -font => 'big',
 )->pack(-side=>'left');
 
 my $entry = $tframe->Entry(
         -show => '*',
         -textvariable => \$passwd,
         -bg => 'black',
         -fg => 'white',
         -font => 'big',
         )->pack(-side=>'left',-expand=>1,-fill=>'x', -padx=> 5);

 my $submit = $tframe->Button(
                 -text=>'Submit',
                 -font => 'big',
                 -bg => 'yellow',
                 -activebackground => 'hotpink',
                 -command => \&submit,
          )->pack(-side=>'right',-expand=>1,-fill=>'x', -padx=> 5);


 for my $row (1..8){
    my $frame = $mw->Frame()->pack(-expand=>1,-fill=>'both');   
   
   for my $col (1..13){
     my $l = shift @keys;
     if($l eq 'dummy'){next}else{
          $frame->Button(-text=> $l,
               -bg => 'beige',
               -activebackground => 'lightyellow',
               -font => 'big',
               -command => [\&process_key, $l],
                 )->pack(-side=>'left',-anchor=>'w', -expand=>1,-fill=
+>'both');   
          
      }
   }
 
 }
MainLoop;
#####################
sub process_key{
  my $key = shift;
  print "$key\n";
  if ($key eq 'Clear'){$passwd = '';}
  elsif ($key eq 'BackSpace'){ chop $passwd;}
  else{ $passwd .= $key;}

}
#####################
sub submit {
 print $entry->get(),"\n";
 $entry->delete(0,'end');
}
Replies are listed 'Best First'.
Re: Tk Virtual Keyboard
by shmem (Chancellor) on Aug 31, 2008 at 15:02 UTC

    Well, xkeycaps has been around some time now... ;)

      Yeah, but it isn't Perl. :-) This allows you to incorporate other Perl code into the script, like encryption code , it may save a pipe being opened. Additionally, xkeycaps may not be available on the machine you may be using (<paranoid>or the xkeycaps may be hacked on the machine</paranoid>) .

      I'm not really a human, but I play one on earth Remember How Lucky You Are
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: snippet [id://670386]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2023-09-29 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?