Sunday, October 14, 2012

Simple Gtk perl to change keyboard layout -- gui

This this my simple to Gtk perl script (GUI) to change keyboard layout in ubuntu.

#!/usr/bin/perl -w

use strict;
use Gtk2 '-init';

use constant TRUE  => 1;
use constant FALSE => 0;

my $window = Gtk2::Window->new('toplevel');
$window->set_title ('chkbd');
$window->signal_connect (destroy => sub { Gtk2->main_quit; });

my $vbox = Gtk2::VBox->new(FALSE, 6);

my $frame = Gtk2::Frame->new('keyboard');
$vbox->pack_start($frame, TRUE, TRUE, 0);

my $hbox = Gtk2::HBox->new(FALSE, 6);

my $inc_button = Gtk2::Button->new('_US');
$hbox->pack_start($inc_button, FALSE, FALSE, 0);
my $count = "US";

my $label = Gtk2::Label->new($count);
$vbox->pack_start($label, TRUE, TRUE, 0);

my $quit_button = Gtk2::Button->new('_KH');
$hbox->pack_start($quit_button, FALSE, FALSE, 0);
$quit_button->signal_connect( clicked => sub {
#        Gtk2->main_quit;
        system("/usr/bin/setxkbmap kh");
        $count = "KH";

# has to be done after we've created the label so we can get to it
$inc_button->signal_connect( clicked => sub {
#        $count++;
        system("/usr/bin/setxkbmap us");
        $count = "US";


this is show only two button, 1, us and 2 kh, and you change change to other keyboard layout, and you can refer to
for more information

No comments:

Post a Comment