Tool to create pdf with current keymap

Thinking about improving the Artwork in Vega Strike, or making your own Mod? Submit your question and ideas in this forum.

Moderator: pyramid

Post Reply
lpet
Insys Pilot
Insys Pilot
Posts: 2
Joined: Sat Jul 22, 2006 2:16 pm

Tool to create pdf with current keymap

Post by lpet »

Hi,
I was a bit tired of not finding a good overview of the keyboard shortcuts to vegastrike. The Manual contains some pages about the default shortcuts, but I think they are hard to read and do not work well for in-game reference. :(

So I wrote a small perl script that reads the current keyboard shortcuts from vegastrike.config and creates a pdf from it (via incorporating LaTeX). It's quite a simple script, but I think especially for beginners it's important to have a list of the shortcuts in paper form. An example of how such a keymap looks like is here:
http://www-e.uni-magdeburg.de/lpeterse/ ... keymap.pdf

Please have a look at this, see if it can be used in the whole Vegastrike-mission.

You can also download the file (if copy-paste is too slow and error-prone) from
http://www-e.uni-magdeburg.de/lpeterse/ ... Keymap.zip

Please note that because this script is written in Perl and needs a full LaTeX-Installation, it might not run in most MS-Windows-environments. A standard Linux Desktop should have all the required programs installed.

So far,
Lars

Edit: OS-Limitation

Code: Select all

#!/usr/bin/perl -w
# File "createVegastrikeKeymap.pl"

use strict;
use Digest::MD5 qw(md5 md5_hex md5_base64);

# This is the path to the vegastrike-config-file. The usual filename is "vegastrike.config" and it is located in the vegastrike-base directory.
$std::configfile="/opt/vegastrike-0.4.3/vegastrike.config";

# this array sorts the keys into a structure. The categories are freely chosen, please edit them to your likings.
%std::commandSorting=(  "Communication" => [ 'ChangeCommStatus','UpFreq','DownFreq','SwitchWebcam','SwitchSecured','Comm1Key','Comm2Key','Comm3Key','Comm4Key','Comm5Key','Comm6Key','Comm7Key','Comm8Key','Comm9Key','CommAttackTarget','CommHelpMeOut','CommBreakForm','CommFormUp','RequestClearenceKey','Cockpit::ScrollDown','Cockpit::ScrollUp' ] ,
                        "Targeting" => [ 'SaveTarget1','SaveTarget2','SaveTarget3','SaveTarget4','SaveTarget5','SaveTarget6','SaveTarget7','SaveTarget8','SaveTarget9','SaveTarget10','RestoreTarget1','RestoreTarget2','RestoreTarget3','RestoreTarget4','RestoreTarget5','RestoreTarget6','RestoreTarget7','RestoreTarget8','RestoreTarget9','RestoreTarget10','TargetKey','SigTargetKey','SubUnitTargetKey','UnitTargetKey','LockTargetKey','PickTargetKey','NearestTargetKey','ReverseTargetKey','TurretTargetKey','ReverseNearestTargetKey','ReverseSigTargetKey','ReverseUnitTargetKey' ] ,
                        "Weaponry and Combat" => [ 'FireKey','SwitchCombatMode','ECMKey','MissileKey','WeapSelKey','ReverseWeapSelKey','TurretControl','ReverseMisSelKey','MisSelKey','TurretAIKey' ] ,
                        "Flight commands" => [ 'JumpKey','ToggleWarpDrive','CloakKey','EjectKey','EjectCargoKey','DockKey','UnDockKey','DecelKey','AccelKey','RollLeftKey','RollRightKey','StopKey','StartKey','UpKey','DownKey','RightKey','LeftKey','RollLeftKey','RollRightKey','ABKey','SetVelocityRefKey','SetVelocityNullKey' ] ,
                        "Navigation" => [ 'Cockpit::MapKey','Cockpit::NavScreen' ] ,
                        "Sound and Music" => [ 'Cockpit::SkipMusicTrack','VolumeInc','VolumeDec','MusicVolumeInc','MusicVolumeDec' ] ,
                        "Game management" => [ 'SuicideKey','TimeInc','TimeReset','PauseKey','Cockpit::Quit' ] ,
                        "Video" => [ 'Screenshot','Cockpit::Inside','Cockpit::InsideLeft','Cockpit::InsideRight','Cockpit::InsideBack','Cockpit::Behind','Cockpit::Pan','Cockpit::OutsideTarget','Cockpit::PanTarget','Cockpit::ZoomIn','Cockpit::ZoomOut','Cockpit::SwitchLVDU','Cockpit::SwitchRVDU','Cockpit::PitchDown','Cockpit::PitchUp','Cockpit::YawLeft','Cockpit::YawRight' ] ,
                        "Others and unknown" => [ 'SwitchControl','SheltonKey' ] );




############################################################################
# Do not change something down here.                                       #
# All necessary/possible settings are to be made in the variables above.   #
# Code belov is for perl-literate people only.                             #
############################################################################



#
# This file "createVegastrikeKeymap.pl" was created by Lars Petersen ( larspet at gmail.com )
# in July 2006. It reads the vegastrike-config file which is in some simple XML-format (it does not parse it,
# just scans through) and prints out a tex-file where the keyboard-shortcuts are sorted into categories
# and arranged on an A4-page so it can easily be printed and viewed.
#
# This Perl-script is little more then a dirty hack. It works, even though it might not be very maintainance-friendly or
# in "good code-style". If you want to enhance it (like add parsing of command-line parameters), please feel free to do so.
# Please notify the author and send your changes, so they can be applied to the original as well and no confusion about
# different versions rises.


# This char splits the keyboard-shortcuts from each other when they are saved in a string.
$std::splitchar="\0";


# this is where the key-shortcuts will be saved (hash of strings)
%std::keys=();

# open infile, scan through to grep the keymappings.
open(INFILE,'<',$std::configfile) or die 'Failed to open infile!.';
my $lineno=0;
while (my $line=<INFILE>) {

        # skip all lines without key bindings
        if (!($line=~/<bind key/)) { next; }

        # clean control characters
        $line=~s/[\t\n\r]//g;

        # skip comments
        if ($line=~/^(<\!--|#|\/\/)/) { next; }

        # print debug
        #print "Line ".($lineno++).": ".$line."\n";

        my $key="";
        my $modifier="";
        my $command="";
        if ($line=~/bind\skey=\"(.*)\"\smodifier=\"(.*)\"\scommand=\"(.*)\"/) {
                $key=$1;
                $modifier=$2;
                $command=$3;
        } elsif ($line=~/bind\skey=\"(.*)\"\scommand=\"(.*)\"/) {
                $key=$1;
                $modifier="none";
                $command="$2";
        }

        my $fullkey=lc($key);

        # If this is an uppercase character (and there exists a lowercase-version), add "Shift" to key-description
        if ( ord(uc($key)) == ord($key) && ord(uc($key)) != ord(lc($key)) ) {
                #print "This key looks uppercase: $key\n";
                $fullkey='Shift-'.$fullkey;
        }
        # add the modifier to the key-description
        if (!($modifier=~/none/i)) {
                $fullkey=ucfirst($modifier).'-'.$fullkey;
        }

        # add found key to collection
        if ( defined($std::keys{$command}) ) {
                my $oldkey= $std::keys{$command};
                $std::keys{$command}=$oldkey.$std::splitchar.$fullkey;
        } else {
                $std::keys{$command}=$fullkey;
        }

}

# Test of the read values
#print "Key-array:\n";
#for my $command (keys(%std::keys)) {
#       print "\tKeys found for Command ".$command.": ";
#       my @keys= split('\0',$std::keys{$command});
#       for my $key (@keys) {
#               print $key.", ";
#       }
#       print "\n";
#}

close(INFILE);

# Test about how to read and cycle through the %std::commandSorting-Hash.
#print "By category:\n";
#for my $cat (keys(%std::commandSorting)) {
#       print $cat.": ";
#       my $count= 0;
#       my $elements= $std::commandSorting{$cat};
#       my $size= $#{$std::commandSorting{$cat}} + 1;
#       for (my $i=0; $i<$size; $i++) {
#               print $elements->[$i].", ";
#       }
#       print "\n";
#}

# Try to create an MD5-Sum of the config file. This is printed on the TeX-Sheet to make it possible to see if
# this shortcut-sheet is still valid. It is not a very good way, as the file also changes when other options are
# changed, like sound or the like. Not really sure about how to make it better.
$std::md5sum_infile="unknown";
if ( open(INFILE,'<',$std::configfile) ) {
        binmode(INFILE);
        my $digest_object= Digest::MD5->new;
        $digest_object->addfile(*INFILE);
        $std::md5sum_infile= $digest_object->hexdigest;
        close(INFILE);
}

# This prints out a TeX-File that contains all the Shortcuts
print "\\documentclass[a4paper,10pt]{article}\n";
print "\\usepackage{lscape,multicol}\n";
print "\\usepackage[textwidth=18cm,textheight=26cm]{geometry}\n";
print "\\setlength{\\parskip}{-0.3cm}\n";
print "\\begin{document}\n";
print "\\begin{landscape}\n";
print "\\pagestyle{empty}\n";
print "\\begin{multicols}{3}\n";
print "[ \\begin{center} \\begin{huge}Keymap chart for vegastrike\\end{huge}\\end{center}\\begin{flushright}Created on: ".gmtime().", Config-file: ".$std::configfile.", MD5SUM: ".$std::md5sum_infile." \\end{flushright} ]\n";
print "\\begin{footnotesize}\n";
for my $cat (sort(keys(%std::commandSorting))) {
        print "\\section{".$cat."}\n";
        print "\\begin{tabbing}\n";
        print "XXXXXXXXXXXX\\hspace{1cm}\\=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \\kill\n";
        my $size= $#{$std::commandSorting{$cat}} + 1;
        for (my $i=0; $i<$size; $i++) {
                print $std::commandSorting{$cat}[$i]."\\>";
                if (defined($std::keys{$std::commandSorting{$cat}[$i]})) {
                        my @keys= split('\0',$std::keys{$std::commandSorting{$cat}[$i]});
                        my $first=1;
                        for my $key (@keys) {
                                # protect slashes, ampersands and other pecial latex-chars
                                $key=~s/(\\)/\\textbackslash/g;
                                $key=~s/(\|)/\\textbar/g;
                                $key=~s/([&])/\\$1/g;
                                if ($first==1) { print $key; $first=0; }
                                else { print ", ".$key; }
                        }
                } else {
                        print "None";
                }
                print "\\\\ \n";
        }
        print "\\end{tabbing}\n";
}
print "\\end{footnotesize}\n";
print "\\end{multicols}\n";
print "\\end{landscape}\n";
print "\\end{document}\n";

# Some help messages
print STDERR "\n";
print STDERR "This script reads the key-bindings from the vegastrike configuration file and writes a TeX (LaTeX)- File that is a nice (one-paper-)Shortcut-List.\n";
print STDERR "To use it, edit the first lines of the file and put in the right location of your vegastrike configuration file and then execute it like this:\n";
print STDERR "\tcreateVegastrikeKeymap.pl > keymap.tex && pdflatex -halt-on-error keymap.tex && acroread keymap.pdf\n";
print STDERR "\n";
Last edited by lpet on Sat Jul 22, 2006 3:10 pm, edited 1 time in total.
loki1950
The Shepherd
Posts: 5841
Joined: Fri May 13, 2005 8:37 pm
Location: Ottawa
Contact:

Post by loki1950 »

lpet great little scprit i imagine that lots of linux users will be useing it as for the windoz users without Perl it's copy paste time :wink: nice to have a perlmonger about 8)

Enjoy the Choce :)
lpet
Insys Pilot
Insys Pilot
Posts: 2
Joined: Sat Jul 22, 2006 2:16 pm

Post by lpet »

loki1950 wrote:lpet great little scprit i imagine that lots of linux users will be useing it as for the windoz users without Perl it's copy paste time :wink: nice to have a perlmonger about 8)

Enjoy the Choce :)


Uups, yeah I forgot to mention the OperatingSystem-Requirements. Guess Windows users will have a hard time using the script. :wink:

BYE
Halleck
Elite
Elite
Posts: 1832
Joined: Sat Jan 15, 2005 10:21 pm
Location: State of Denial
Contact:

Post by Halleck »

Awesome... we should run this script before every release and include the outputted PDF. "Quick reference chart generator" I suppose.

How hard would it be to make it output a text file instead? Might be useful for people who have perl for windows, or linux users who don't have LaTeX installed.
Post Reply