X11-Keyboard-1.4/0040755000076400007640000000000007573325171012511 5ustar ekkisekkisX11-Keyboard-1.4/README0100644000076400007640000000135707573325142013372 0ustar ekkisekkisX11-Keyboard version 1.4 ======================== This module make available certain keyboard functions useful to translate keysyms and keycodes, when working with the X11::Protocol module. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES 1. the X11::Protocol module DOCUMENTATION For docs please see man page: # man X11::Keyboard COPYRIGHT AND LICENCE Copyright (C) 2002 Erick Calder This product is distributed under the MIT License. A copy of this license was included in a file called LICENSE. If for some reason, this file was not included, please see http://www.opensource.org/licenses/mit-license.html to obtain a copy of this license. X11-Keyboard-1.4/Makefile.PL0100644000076400007640000000053507573234626014467 0ustar ekkisekkisuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'X11::Keyboard', VERSION_FROM => 'Keyboard.pm', AUTHOR => 'Erick Calder ', ABSTRACT_FROM => 'Keyboard.pm', PREREQ_PM => { X11::Protocol => '0.04', }, ); X11-Keyboard-1.4/Changes0100644000076400007640000000200307573325130013767 0ustar ekkisekkisRevision history for Perl extension X11-Keyboard. ============================================================================= revision 1.4 date: 2002/12/04 05:16:01; author: ekkis; state: Exp; lines: +10 -8 - methods now default required args to $_ ---------------------------- revision 1.3 date: 2002/12/04 04:36:30; author: ekkis; state: Exp; lines: +29 -16 - KeysymToKeycode() now returns state - added Acknowledgements section ---------------------------- revision 1.2 date: 2002/12/03 23:19:48; author: ekkis; state: Exp; lines: +12 -7 - first pass. made sure module compiles and test works ---------------------------- revision 1.1 date: 2002/12/03 23:09:10; author: ekkis; state: Exp; branches: 1.1.1; Initial revision ---------------------------- revision 1.1.1.1 date: 2002/12/03 23:09:10; author: ekkis; state: Exp; lines: +0 -0 Imported sources ============================================================================= 0.01 Tue Sep 10 03:44:09 2002 - original version; created by h2xs 1.21 X11-Keyboard-1.4/MANIFEST0100644000076400007640000000007007573234626013640 0ustar ekkisekkisChanges Makefile.PL MANIFEST Keyboard.pm README test.pl X11-Keyboard-1.4/test.pl0100644000076400007640000000127707573317220014025 0ustar ekkisekkis#!/usr/bin/perl # test suite use Test::Simple tests => 8; use X11::Protocol; $x = X11::Protocol->new(); ok(defined $x && $x->isa('X11::Protocol'), "connection established"); use X11::Keyboard; ok(1, 'use X11::Keyboard'); $k = X11::Keyboard->new($x); ok(defined $k && $k->isa('X11::Keyboard'), "component instantiated"); $keysym = $k->StringToKeysym("plus"); ok($keysym, "string converted"); $keycode = $k->KeysymToKeycode($keysym); ok($keycode, "keycode generated"); @keycode = $k->KeysymToKeycode($keysym); ok($keycode[1], "state generated"); # or, more simply $keycode2 = $k->KeysymToKeycode("plus"); ok($keycode == $keycode2 && $keycode == $keycode[0], "keycode translation"); ok(1, "done"); X11-Keyboard-1.4/Keyboard.pm0100644000076400007640000000760607573307621014615 0ustar ekkisekkis# # Copyright (c) Erick Calder, 2002. # All rights reserved. # =head1 NAME X11::Keyboard - Keyboard support functions for X11 =head1 SYNOPSIS use X11::Protocol; use X11::Keyboard; $x = X11::Protocol->new(); $k = X11::Keyboard->new($x); $keysym = $k->StringToKeysym("plus"); print $k->KeysymToKeycode($keysym); # or, more simply print $k->KeysymToKeycode("plus"); =head1 DESCRIPTION This module is meant to provide access to the keyboard functions of X11. Whilst the functions names are essentially identical to those used in xlib (minus the prepended X), the parameter lists and return values are different as specified in this document. =cut package X11::Keyboard; # --- external modules -------------------------------------------------------- use warnings; use strict; use X11::Keysyms '%keysyms'; # --- module variables -------------------------------------------------------- use vars qw($VERSION %keysyms); $VERSION = substr q$Revision: 1.4 $, 10; # --- module interface -------------------------------------------------------- =head1 METHODS An object oriented interface is provided as follows: =head2 new Used to initialise the system, this method requires a handle to an X connection (typically generated using the X11::Protocol module) and returns an object instance. =cut sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = bless({}, $class); $self->{x} = shift; warn "No X connection available!" unless $self->{x}; $self->{sym2cd} = $self->GetKeyboardMapping(); return $self; } =head2 keysym-num = StringToKeysym [keysym-name = $_] This method requires a keysym name and returns its corresponding numeric value. If no name is provided, B<$_> is used. I<- exempli gratia -> $c = $k->StringToKeysym("Backspace"); # $c now contains 65288 =cut sub StringToKeysym { my ($self, $s) = @_; $keysyms{$s || $_}; } =head2 keycode [state] = KeysymToKeycode [keysym-[num|name] = $_] This method returns the keycode corresponding to the passed-in keysym name or number (if neither is passed B<$_> is used). In such cases where the keysym name evaluates to a numeric value e.g. [0-9], the caller is responsible for first converting the value to a true keysym-num. The method can also return the associated state. If the calling context is a list it is returned, if scalar, only the keycode is returned. =cut sub KeysymToKeycode { my ($self, $keysym) = @_; $keysym ||= $_; $keysym = $self->StringToKeysym($keysym) unless $keysym =~ /^[0-9]+$/; wantarray() ? @{$self->{sym2cd}{$keysym}} : $self->{sym2cd}{$keysym}[0]; } # --- internal functions ------------------------------------------------------ sub GetKeyboardMapping { my $self = shift; my $x = $self->{x}; my $min = $x->{min_keycode}; my $count = $x->{max_keycode} - $min; my @mapping = $x->GetKeyboardMapping($min, $count); die "No keyboard map!" unless @mapping; my %ret; for my $i (0 .. $#mapping) { $ret{$mapping[$i][0]} = [$i + $min, 0]; # unshifted $ret{$mapping[$i][1]} = [$i + $min, 1]; # shifted } wantarray() ? %ret : \%ret; } 1; # :) __END__ =head1 AUTHOR Erick Calder =head1 ACKNOWLEDGEMENTS My gratitude to Benjamin Goldberg for his patience and direction in my struggles to put this together, as well as to Somni and dkr from the OPN #perl channel. =head1 AVAILABILITY + SUPPORT For support e-mail the author. This module may be found on the CPAN. Additionally, both the module and its RPM package are available from: F =head1 DATE $Date: 2002/12/04 05:16:01 $ =head1 VERSION $Revision: 1.4 $ =head1 LICENSE AND COPYRIGHT Copyright (c) 2002 Erick Calder. This product is distributed under the MIT License. A copy of this license was included in a file called LICENSE. If for some reason, this file was not included, please see F to obtain a copy of this license.