1a. Introduction.
The Linux console provides a number of "virtual terminals" (VTs) which can be accessed with the key combination
Alt-Fn (
n=1,2,...). FreeBSD provides a similar facility with the same keystrokes.
In NetBSD and OpenBSD the default console is called wsconsole (short for WorkStation console), and provides several virtual screens that are accessed with the key combination
Ctrl-Alt-Fn.
Neither of these two key combinations is "right or wrong", and which is "better" depends on what you're used to. New users coming to NetBSD or OpenBSD who are used to the Linux convention
Alt-Fn may find it frustrating to have to also press
Ctrl- to switch screens. This can be particularly true when simultaneously working on two machines which use different conventions.
This guide will show how to change the NetBSD or OpenBSD screen switching keys to
Alt-Fn, which I find to be easier. The basic principles on the two OS's are the same, but the syntax differs in places.
1b. Purpose and scope.
This guide is intended to be practical, rather than perfect.
2a. Changing the NetBSD key map on the fly.
This subsection focuses on NetBSD. The modifications for OpenBSD are summarized in the next subsection.
The keyboard mapping can be inspected, and changed, using the
wsconsctl(8) command as root. For NetBSD this command may use the
-k flag to access the keyboard (rather than the mouse or display), but
-k can be left off since it's the default.
The existing keyboard map can be inspected with
# wsconsctl -k map | less
Of particular interest to the topic at hand is to find map entries containing the items
Cmd1,
Cmd2 and
Cmd. For example, on my machine I get this output:
# wsconsctl map | grep Cmd1
keycode 29 = Cmd1 Control_L
# wsconsctl map | grep Cmd2
keycode 56 = Cmd2 Alt_L
This means the left
Ctrl key also acts as
Cmd1 and the left
Alt key also acts as
Cmd2. By default,
Cmd1 and
Cmd2 are both required together with
Fn to switch virtual screens.
We want to change this so there is only a single
Cmd key required, on
Alt. I'll show how to do this in the context of the above example; if your keycodes are different, then make the appropriate changes. To do this we get rid of
Cmd1 on left
Ctrl (keycode 29), get rid of
Cmd2 on left
Alt (keycode 56) and add
Cmd to left
Alt. This can be done with the commands:
# wsconsctl -w map+="keycode 29 = Control_L"
# wsconsctl -w map+="keycode 56 = Cmd Alt_L"
The
-w flag tells wsconsctl to write the changes to the map.
Doing the above should allow any wsconsole commands previously accessible with
Ctrl-Alt-* to be invoked with just left
Alt-*, including switching screens with
Alt-Fn, but this will only stay in effect for the current boot-up.
2b. Modifications for OpenBSD.
On OpenBSD, wsconsctl has no
-k or
-w flags. The syntax is
# wsconsctl keyboard.map | less
etc., and
# wsconsctl keyboard.map+="keycode 29 = Control_L"
# wsconsctl keyboard.map+="keycode 56 = Cmd Alt_L"
You may want to change
Control_R and
Alt_R as well.
3. Making the changes permanent.
If you want these changes to take effect automatically every time you boot, put them in the appropriate config files.
I begin with NetBSD. First, define a keyboard map file by adding the following line, or similar, into
/etc/wscons.conf,
Code:
mapfile /etc/wscons-keymap.local
Second, create
/etc/wscons-keymap.local if it doesn't exist and add the following entries into it
Code:
# Change Cmd_ "prefix" from Ctrl+Alt- to Alt- (all Left)
# This is done by using Cmd rather than Cmd1 and Cmd2 !
# Remove first entry Cmd1 on RHS for left Control key:
keycode 29 = Control_L
# Remove first entry Cmd2 on RHS for left Alt key, and add Cmd:
keycode 56 = Cmd Alt_L
# Above could make Alt-Esc enter the debugger (dangerous?)
# so let's turn off this capability which I never use anyway.
# Remove first entry Cmd_Debugger on RHS:
keycode 1 = Escape
Note, I've added a tweak so that
Alt-Esc doesn't trigger the debugger by accident, as this could happen more easily than with
Ctrl-Alt-Esc. If you don't want this change omit the
"keycode 1 = Escape" stuff.
Turning to OpenBSD, it's only necessary to modify a single config file,
/etc/wsconsctl.conf,
to which changes in the form
variable+=value are added, e.g.:
Code:
keyboard.map+="keycode 29 = Control_L"
keyboard.map+="keycode 56 = Cmd Alt_L"
keyboard.map+="keycode 1 = Escape"
4. References.
wscons(4)
wsconsctl(8)
wscons.conf(5) [NetBSD]
wsconsctl.conf(5) [OpenBSD]
/usr/include/dev/wscons/wsksymdef.h
OpenBSD FAQ Section 7.1 is minimalist.
5. Disclaimers.
* I have had this not work on an HP USB wireless keyboard.
* I never tried to change the Linux keys to
Ctrl-Alt-Fn.
* I don't have a deep understanding of BSD wsconsole key mapping, as I didn't find any clear, friendly and thorough documentation. A study of the source code may be needed to learn more.
* Comments, criticisms, suggestions, etc., are welcome.