[comp.sys.mac.programmer] Solution: swapping keys on extended keyboard

jxf@altair.cis.ksu.edu (Jerry Frain) (01/03/91)

A while back I posted a request for help swapping the control key
and caps lock key on the Apple extended keyboard.

I didn't receive any replies on how to _logically_ swap the keys
(I did receive one very helpful reply on how to physically swap the
lock-down mechanism), so I thought I'd post the solution in case
anyone else is interested.

The only references I found were Apple Tech Note #160, and IM-V,
pages 190-193.  They proved to be quite adequate (once I found
them).

Basically, there is a KMAP resource in the System file which maps the
raw key codes to "virtual" key codes.  The fourth byte offset of the
KMAP resource ID #2 in the System file begins a 128-byte array of
virtual key codes (see tech note #160).  The raw key code is used as
an index to this array.

The eighth line of this resource (from ResEdit) looks like this:

        000038  3435 3B37 38B9 3A7B

Swap the fourth and sixth bytes so that the line looks like this:

        000038  3435 B937 383B 3A7B
                     ^^     ^^

These two bytes are the "virtual key codes" for the control key, and
caps lock key, respectively.

That's all there is to it.

  --Jerry

--
Jerry Frain -- Systems Programmer               Kansas State University
                                        Department of Computing & Info Sciences
Internet : jxf@cis.ksu.edu                         Manhattan, Kansas
UUCP     : ...!rutgers!ksuvax1!jxf

russotto@eng.umd.edu (Matthew T. Russotto) (01/04/91)

In article <1991Jan3.084459.24275@maverick.ksu.ksu.edu> jxf@altair.cis.ksu.edu (Jerry Frain) writes:
>
>A while back I posted a request for help swapping the control key
>and caps lock key on the Apple extended keyboard.
>
>I didn't receive any replies on how to _logically_ swap the keys
>(I did receive one very helpful reply on how to physically swap the
>lock-down mechanism)
Say, could you post that in comp.sys.mac.hardware????

, so I thought I'd post the solution in case
>anyone else is interested.
>
>The only references I found were Apple Tech Note #160, and IM-V,
>pages 190-193.  They proved to be quite adequate (once I found
>them).
>
[the hard way of using ResEdit to do it omitted].

Hate to tell you this, but ResEdit 2.0 has a KCHR editor that would have
allowed you to do so in a much more intuitive way.
--
Matthew T. Russotto	russotto@eng.umd.edu	russotto@wam.umd.edu
     .sig under construction, like the rest of this campus.

jxf@altair.cis.ksu.edu (Jerry Frain) (01/04/91)

russotto@eng.umd.edu (Matthew T. Russotto) writes:

>In article <1991Jan3.084459.24275@maverick.ksu.ksu.edu> jxf@altair.cis.ksu.edu (Jerry Frain) writes:
>>
>>A while back I posted a request for help swapping the control key
>>and caps lock key on the Apple extended keyboard.
>>
>>I didn't receive any replies on how to _logically_ swap the keys
>>(I did receive one very helpful reply on how to physically swap the
>>lock-down mechanism)

>Say, could you post that in comp.sys.mac.hardware????

Sure thing, I'll take care of that as soon as I finish this follow-up.

[ I (logically) swapped the keys by swapping virtual keycodes in KMAP ]

>[the hard way of using ResEdit to do it omitted].

Not really hard, only about 20 seconds of my time once I figured out
what I wanted to change was in KMAP.

>Hate to tell you this, but ResEdit 2.0 has a KCHR editor that would have
>allowed you to do so in a much more intuitive way.

Um, maybe, but it wasn't to my satisfaction.  As I understand it, KCHR is
a table for mapping virtual keycodes to the ascii values.  I, however,
modified the KMAP resource which interprets the raw keycodes to virtual
keycodes.

IMHO, Apple screwed up by placing the caps lock and control key where
they are (were :-) on the extended keyboard.  I permanently modified
the keyboard, and modifying the virtual keycodes comes as close as I
can (without some fancy hardware work) to permanently modifying the
key mapping.

Now, when I use ResEdit to look at the KCHR resource, I press the control
key and ResEdit highlights *the caps lock key*.  Neato, eh?  Hence, I went
one level lower in the key mappings than KCHR lets me go, and that's right
where I wanted my key mapping -- as close to the hardware as possible.

Cheers,

  --Jerry

--
Jerry Frain -- Systems Programmer               Kansas State University
                                        Department of Computing & Info Sciences
Internet : jxf@cis.ksu.edu                         Manhattan, Kansas
UUCP     : ...!rutgers!ksuvax1!jxf