Fs2 open on Linux/I18n and Key mapping problems
« ERROR: "Web cursor bitmap not found." | The fs2_open on Linux Guide I18n and Key mapping problems |
Dedicated X Display » |
Ok, imagine that like me you don't have an us keyboard but a french one (or anything). Well, you probably have problems mapping some keys or even using the default mapping.
Actually, the problem is fs2_open does not take modifiers into account, as it uses them internally as modifiers for keys, and it won't accept non-us charset either.
On a french keyboard layout, the numbers 1 2 3 4 5 6 7 8 9 0 are on the same keys than on a US layout, but you have to press shift to use them. The primary function for theses keys are & é " ' ( - è _ ç à ). These characters won't be accepted by freespace, and if you press shift to get a number, it won't work. This can be a problem, as theses keys are needed to use the communication system, and cannot be bound to anything. Also, as you won't get access some keys on your keyboard, it will be difficult to map every command on a key, or you'll have to use modifiers for nearly each key.
However, there is a solution. You can tell X to remap the keyboard before launching the game, and restore your normal keymap afterwards.
For exemple, I map 123456790 to &é"'(-è_çà keys so I can use the communication system, and I put , and ; on the Alt-Gr and Menu keys for convenience, as I binded thoses keys to next primary weapon and next secondary weapon.
To do this, I use a slightly enhanced startup script, which I put in ~/bin (this directory is in my path), together with a customized xmodmap.
- First, dump your current xmodmap :
~ $ xmodmap -pke > ~/xmodmap.current
- Then edit it with your favorite text editor. You'll see a bunch of lines looking like this :
keycode 8 = keycode 9 = Escape keycode 10 = 1 ampersand onesuperior exclamdown onesuperior exclamdown
The syntax is keycode <number> = <symbol list>.
Use xev to scan the keycodes. The symbols are defined in /usr/include/X11/keysymdef.h. Just make sure you write them without the XK_ prefix. You'll find more information about xmodmap in the xmodmap manual page.
Just modify the keys you need, and be patient. This can be a long process. Test it with xmodmap :
~ $ xmodmap - < <filename>
But don't forget to have your previous keymap at hand to recover your settings ! If you mess everything up, just restart X. Your default keymap will be applied from the X configuration.
Here is my own fs2 xmodmap, derived from fr-latin1 as described above. Feel free to use it if you're too lazy to modify your own. However, it may not fit with your needs. You may always use it as an exemple, thougt.
Then, when the file is modified at your liking, just save it as ~/.fs2_open/xmodmap
We'll start fs2_open with a slightly more elaborate startup script which will backup/apply/restore the keymap in addition of running the games with some options in the right directory.
#!/bin/sh # This script lauches fs2. If there is a file named $FS2_modmap (see below), # backup the current modmap as $TMP_modmap and load it as the new modmap. # The current modmap will be restored afterwards. TMP_modmap="$HOME/xmodmap.tmp" FS2_modmap="$HOME/.fs2_open/xmodmap" FS2_OPEN_DIR=/usr/local/games/fs2_open FS2_ARGS="-glow -spec -spec_exp 11 -spec_point 0.6 -spec_static 0.8 -spec_tube 0.4 \ -fps -jpgtga -ambient_factor 75 -targetinfo -nograb" FS2_BIN="$FS2_OPEN_DIR/fs2_open_r" die() { echo "** Fatal error : $1" >&2 exit 1 } cd $FS2_OPEN_DIR || die "Could not change directory to $FS2_OPEN_DIR" # dump current xmodmap [ -f "$FS2_modmap" ] && xmodmap -pke > $TMP_modmap # load xmodmap [ -f "$FS2_modmap" ] && xmodmap - < $FS2_modmap # prepare to restore xmodmap on crash or exit trap "xmodmap - < $TMP_modmap && rm $TMP_modmap" 0 2 3 4 9 11 15 # launch fs2 $FS2_BIN $FS2_ARGS $* || die "Error while running \"$FS2_BIN\" with arguments \ \"$FS2_ARGS\" ($?)"
Adapt this script to your needs, and save it somewhere in your PATH - I for exemple use ~/bin/freespace2. Make it executable with chmod +x <file>
That's it, now you can use fs2 with full control over your keyboard.