Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I would like to map the Command key to the Control key but, have it affective only while running a WINE application using the new 'Mac Driver', not X11. I tried a registry edit but, I don't know what I'm doing and google hasn't been very helpful.

No third party software! I don't want to hear about anything like KeyRemap4MacBook.

share|improve this question

2 Answers 2

I was looking to solve the same issue in order to use the same hotkeys inside Wine as for regular OS X applications. No information on that is available from what I can tell so the easiest solution turned out finding the source code of winemac.drv. The important function is macdrv_compute_keyboard_layout() which does lots of various computations but for the modifier keys it all essentially boils down to taking values from default_map (all modifier keys are marked as "fixed"). Unfortunately, as of Wine 1.7.10 there is no configurability here so the map values have to be changed by modifying the compiled file.

For me the compiled file was located under /Applications/Wine.app/Contents/Resources/lib/wine/winemac.drv.so. It's generally a good idea to create a copy of the original file before changing it. You need a hex editor to open it. First let's have a look at the following two lines:

{ VK_RMENU,                 0x38 | 0x100,   TRUE },     /* kVK_RightCommand */
{ VK_LMENU,                 0x38,           TRUE },     /* kVK_Command */

According to the virtual key table VK_RMENU has the value 0xA5 and VK_LMENU the value 0xA4. In other words, the binary representation of these two lines looks like this:

A5 00 38 01 01 00 00 00
A4 00 38 00 01 00 00 00

I found this byte sequence at the offset 0x62770, for your Wine build things might be slightly different. We want to map the Command key to VK_LCONTROL and VK_RCONTROL meaning that these two entries have to be changed into:

A3 00 1d 01 01 00 00 00
A2 00 1d 00 01 00 00 00

Now I would also like to map the Option key to Alt because I need a working Alt key. By default both Option keys are unmapped, meaning that they are represented by a sequence of eight zeroes in the table and need to be found by position. The left Option key is the third entry after left Command, the right Option key is the sixth entry after left Command (for me offset 0x62790 and 0x627A8 respectively). The first entry can be changed into:

A4 00 38 00 01 00 00 00

And the second into:

A5 00 38 01 01 00 00 00

Yes, these are the values originally assigned to the Command key. I actually only changed the entry for the left Option key, this way the right Option key can still be used to produce special characters.

This isn't a great solution, more of a hack that will have to be repeated each time Wine is updated. Also, remapping the Option key only works for keyboard shortcuts like Alt-F4 but not for Alt-F. Still, it does the job for now and in future Wine developers will hopefully add some configuration here. I filed the corresponding change request as bug 35351.

share|improve this answer

Wladimir's answer (and other help he provided on his own site) made it easy to put together a modified copy of the source code, so that the Mac driver maps the Alt key to the Option key and the Win key to the Cmd key, plus a patched copy of the winemac.drv.so file. Details here:

http://www.columbia.edu/~em36/winekeymap.html

All credit goes to Wladimir. I just put together the information he supplied.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.