Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: The most useless key on my keyboard is:

by liverpole (Monsignor)
on Dec 06, 2005 at 14:22 UTC ( #514459=note: print w/ replies, xml ) Need Help??


in reply to The most useless key on my keyboard is:

For anyone who's interested, here's a script which will disable the Caps Lock key under Linux, or turn it back on.  The default is to apply it only to the current user; to make the change global, the -g switch is used.

#!/usr/bin/perl -w # # Disable/Enable the caps lock key # 051206 liverpole # ############## ### Strict ### ############## use strict; use warnings; #################### ### User-defined ### #################### my $xmodmap = '/usr/bin/X11/xmodmap'; my $sysmodmap = '/etc/X11/Xmodmap'; my $usrmodmap = $ENV{'HOME'} . "/.Xmodmap"; ################# ### Libraries ### ################# use FileHandle; use File::Basename; use Getopt::Long; ############### ### Globals ### ############### my $iam = basename $0; my $b_global = 0; my $syntax = " syntax: $iam [switches] <'off' | 'on'> Disables or reenables the CAPS LOCK key by changing the appropriat +e 'Xmodmap' file. Use 'off' to disable, and 'on' to reenable. Switches: -g ... apply the change globally (must be run as 'root' +) "; #################### ### Command-line ### #################### GetOptions("g" => \$b_global) or die $syntax; (my $state = shift) or die $syntax; if ($state ne 'off' && $state ne 'on') { die "$iam: invalid state '$state' (should be 'off' or 'on')\n"; } ################### ### Subroutines ### ################### sub perform($) { my ($cmd) = @_; print "% $cmd\n"; system($cmd) } #################### ### Main program ### #################### # If making global changes, make sure user is 'root' if ($b_global) { (0 == $<) or die "$iam: you must run this as 'root'\n"; } # Read the appropriate file my $infile = ($b_global || (!-e $usrmodmap))? $sysmodmap: $usrmodmap; my $fh = new FileHandle; open($fh, "<", $infile) or die "$iam: cannot read '$infile' ($!)\n"; chomp(my @lines = <$fh>); close $fh; printf "Read '$infile' -- %d line%s\n", 0 + @lines, (1 == @lines)? "": + "s"; # Modify the file @lines = grep { !/^\s*(remove|add)\s+Lock\s+=\s+Caps_Lock\s*(!|$)/i } +@lines; ($state eq 'off') and push @lines, "remove Lock = Caps_Lock"; ($state eq 'on') and push @lines, "add Lock = Caps_Lock"; # Write the file my $outfile = $b_global? $sysmodmap: $usrmodmap; open($fh, ">", $outfile) or die "$iam: cannot write '$outfile' ($!)\n +"; map { print $fh "$_\n" } @lines; printf "Wrote '$outfile' -- %d line%s\n", 0 + @lines, (1 == @lines)? " +": "s"; close $fh; # Make the changes take effect if (-x $xmodmap) { (-f $sysmodmap) and perform "$xmodmap $sysmodmap"; (-f $usrmodmap) and perform "$xmodmap $usrmodmap"; }

@ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"


Comment on Re: The most useless key on my keyboard is:
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2015-07-31 01:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls