Keys and remapping them (was Re: Daydreaming)
Keys and remapping them (was Re: Daydreaming)
- Subject: Keys and remapping them (was Re: Daydreaming)
- From: William Mortensen <email@hidden>
- Date: Tue, 20 Nov 2007 17:42:11 -0800
On Nov 20, 2007, at 2:59 PM, Nathaniel Gray wrote:
On Nov 20, 2007 12:12 PM, Derek Fawcus <email@hidden> wrote:
On Tue, Nov 20, 2007 at 07:09:50PM +0100, Harald Hanche-Olsen wrote:
No: Only to one of four predefined modifiers, or to nothing at all.
And then it is utterly undistinguishable from the other modifier
key(s) similarly defined. How I would love to be able to give
different definitions to the left and right command keys ...
Hmm - is it command that only has the one virtual keycode?
I believe some of the others (ctrl, shift, alt?) have two, and some
OSX apps can distinguish between them.
Certainly the mac keyboards generate seperate scan codes (X under
Linux
on my MacBook could distinguish the keys).
xev shows me different scan codes and key bindings for left/right
shift, cmd, and option. Control is swapped with caps-lock on my
machine, but I'll bet I would get separate codes for Control_L and _R.
This may have changed since Tiger -- I seem to remember not being able
to distinguish them before.
This is hardware-dependent. I believe Apple's desktop USB keyboards
send different keycodes for left and right modifiers. On the other
hand, ADB-based laptop keyboards, as found on all iBooks and
PowerBooks until 2005, always send the keycode for the left modifier.
In 2005 the 15" and 17" PowerBook switched to a USB-based keyboard
while the 12" PB and the iBooks stayed with the ADB keyboard. Judging
by the developer notes, this new keyboard had the same problem.
However, on both types of keyboard, holding down the Fn key in
combination with Ctrl or Shift sends the keycodes for right-Ctrl and
right-Shift, as described at (for example) <http://developer.apple.com/documentation/Hardware/Developer_Notes/Macintosh_CPUs-G4/iBookG4/3_Input-Output/chapter_4_section_12.html
>. Perhaps this could help to alleviate the modifier shortage.
It appears that MacBooks and MacBooks Pros also use a USB-based
keyboard, but I don't know if it's the same one as the late PowerBooks
used.
It is also possible to remap the keys on an ADB-based laptop keyboard
as described at <http://snark.de/index.cgi/0007>, subject to the
hardware limitations mentioned above. Note that this still works on
Leopard (I successfully remapped my 12" PowerBook's useless Enter key
to an Option key).
I suspect that the same thing can be accomplished for at least some
USB-based laptop keyboards by modifying /System/Library/Extensions/
AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/Contents/
Info.plist, though you would have to figure out which of the several
dictionaries inside IOKitPersonalities to modify for your particular
machine. It looks like for 2007 Apple keyboards you would check out /
System/Library/Extensions/AppleHIDKeyboard.kext/Contents/Info.plist. I
can't actually figure out what kext gets loaded for generic USB
keyboards; I think there used to be an AppleUSBKeyboard.kext but it
doesn't exist anywhere in /System/Library/Extensions anymore. Maybe
that functionality got moved somewhere else.
BTW, if you really want to go nuts with keyboard remapping, look at
the event taps API. I wrote a 100-line program that swaps ctrl and
cmd in Terminal.app (and *only* in Terminal.app) without any code
injection, input managers, or unsupported APIs. You can just as
easily do system-wide filtering. My modded my code and wrote a filter
that remaps the numeric keypad to match the space numbers in a 3x3
spaces layout (1 2 3 on top, 7 8 9 on bottom), and it only takes
effect if the ctrl key is held down. Fun stuff.
I don't really have a need to do this, but I would like to learn more
about how you did it. :-)
Will
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
This email sent to email@hidden