Corrected keyboard mapping for Wine under OS  X

The problem: incorrect mapping of Alt and Win keys in Wine

By default, Windows applications that are run under Wine in OS X use a confusing system of mapping keys on the Mac keyboard to keystrokes sent to the application.

In Wine, by default, in order to send a keystroke such as Alt-F1 to a Windows application, you must type Cmd-F1 on the Mac keyboard. The Option key on the Mac does nothing, and there is no way to send a Win-key keystroke. This problem occurs both with the Mac driver and with the X11 driver supplied with the superb Wineskin wrapper software (and presumably with other Wine implementations).

A solution for the Wine Mac driver

In order to correct the keyboard mapping in the native Mac driver for Wine, you may either use a patched version of one of the files used by the driver, or build a corrected version of the driver from the Wine source code.

The simplest way to fix the problem is to use a patched version of the file, which may be downloaded from this link. It is a patched copy of the file as supplied with version 1.8. (And it appears to work correctly under Wine 2.0.)The patch is based on these instructions from Wladimir Palant. Use the OS X Finder to locate the original version of this file on your system (it is deep inside the directory structure of a Wineskin wrapper); make a backup copy of the original, and replace it with the patched version.

Expert users will want to build their own copy of the driver (or of the complete Wine software). To do so, replace the keyboard.c file in the source code with the corrected version which may be downloaded from this link. The four modified lines are the ones that include comments that begin //was

If you know how use the source code, you will not need detailed instructions. You may either build all of Wine or merely the winemac driver. To build the driver only, from the top-level directory of the source code (basic detail only):

./configure --without-x --without-png --without-freetype make dlls/winemac.drv/Makefile cd dlls/winemac.drv make

A solution for the X11 driver

The same erroneous keyboard mapping occurs with the X11 driver for Wine that is used in Wineskin (and presumably other Wine implementations). The solution for Wineskin wrappers is as follows (I have not experimented with a full, separate Wine installation):

You must create a new .Xmodmap file (note the dot at the start of the name) and write it to the Frameworks folder inside the Contents folder inside your Wineskin. The easiest way to do this is as follows.

First, create a text file named Xmodmap (no dot!) inside the Frameworks folder of your Wineskin; use the following as the contents of the file (the first two lines are comments and may be omitted):

! keycodes 63 and 71 are left and right command keys ! keycodes 66 and 69 are left and right alt keys keycode 63 = Super_L keycode 71 = Super_R keycode 66 = Alt_L Meta_L keycode 69 = Alt_R Meta_R clear mod1 clear mod4 add mod1 = Alt_L Alt_R add mod4 = Super_L Super_R

Next, go to System Preferences, Keyboard, Shortcut, and, under Services, Files and Folders, add a checkmark next to New Terminal at Folder. Then, with the Frameworks folder selected in the Finder, ctrl-click and choose New Terminal at Folder from the Services menu.

Inside the Terminal window, enter the following command:

cp Xmodmap .Xmodmap

Note the dot at the start of the target filename. This creates an invisible ".Xmodmap" file as a copy of the visible file that you created earlier. Let the visible file remain in the folder so that you can easily edit it and recopy it later if needed.

Edward Mendelson (em thirty-six [at] columbia [dot] edu, but with two initials and two numerals before the [at] sign, not spelled out as shown here).