Full Key Codes is a very handy utility for finding the key code for any key on your keyboard that has one. When reading someone else’s script, however, it is not always easy to tell what key is meant by a key code instruction in the script. To solve that problem for my keyboard, I wrote two scripts. The first below prepares a list of all the key codes with values given an experimentally determined set, and the second then reveals the key corresponding to any code if there is one. In my preliminary testing the results seemed to be accurate, but I did not test every key.
If you have an American Apple Pro USB Keyboard, the second script can be used as is.
(* The nested list below was determined for the standard Apple Pro USB Keyboard delivered with a G5-2/2.3 tower. System Profiler describes it as follows:
Apple Pro Keyboard:
Version: 4.10
Bus Power (mA): 250
Speed: Up to 12 Mb/sec
Manufacturer: Mitsumi Electric
Product ID: 0x020b
Vendor ID: 0x05ac (Apple Computer, Inc.)
Using Full Key Codes found here [http://softwares.bajram.com/utilities/] the list below was determined by simply pressing every key and recording what the text on the key cap and the decimal key code that went with it. Note that neither F14 nor F15 produced a code on my machine, and that the volume softer, volume louder, mute volume and eject did not either - they simply did what they were supposed to do. Finally, although the modifier keys: Caps Lock, Shift, Control, Option, and Command have key codes in a standard ISO set, they are not displayed by Full Key Codes.
*)
set FullKeySet to {{"esc", 53}, {"F1", 122}, {"F2", 120}, {"F3", 99}, {"F4", 118}, {"F5", 96}, {"F6", 97}, {"F7", 98}, {"F8", 100}, {"F9", 101}, {"F10", 109}, {"F11", 103}, {"F12", 111}, {"F13", 105}, {"'~", 50}, {"1!", 18}, {"2@", 19}, {"3#", 20}, {"4$", 21}, {"5%", 23}, {"6^", 22}, {"7&", 26}, {"8*", 28}, {"9(", 25}, {"0)", 29}, {"-_", 27}, {"=+", 24}, {"Del", 51}, {"Tab", 48}, {"qQ", 12}, {"wW", 13}, {"eE", 14}, {"rR", 15}, {"tT", 17}, {"yY", 16}, {"uU", 32}, {"iI", 34}, {"oO", 31}, {"pP", 35}, {"[{", 33}, {"]}", 30}, {"\\|", 42}, {"aA", 0}, {"sS", 1}, {"dD", 2}, {"fF", 3}, {"gG", 5}, {"hH", 4}, {"jJ", 38}, {"kK", 40}, {"lL", 37}, {";:", 41}, {"'\"", 39}, {"Return", 36}, {"zZ", 6}, {"xX", 7}, {"cC", 8}, {"vV", 9}, {"bB", 11}, {"nN", 45}, {"mM", 46}, {",<", 43}, {".>", 47}, {"/?", 44}, {"Space", 49}, {"F16", 106}, {"Help", 114}, {"Home", 115}, {"page up", 116}, {"Fwd Del", 117}, {"end", 119}, {"page down", 121}, {"up arrow", 126}, {"left arrow", 123}, {"right arrow", 124}, {"down arrow", 125}, {"clear", 71}, {"N: =", 81}, {"N: /", 75}, {"N: *", 67}, {"N: -", 78}, {"N: +", 69}, {"Enter", 76}, {"N: .", 65}, {"N: 0", 82}, {"N:1", 83}, {"N: 2", 84}, {"N: 3", 85}, {"N: 4", 86}, {"N: 5", 87}, {"N: 6", 88}, {"N: 7", 89}, {"N: 8", 91}, {"N: 9", 92}}
-- split the entries into two corresponding lists
set KK to {}
set KN to {}
repeat with K in FullKeySet
set end of KK to item 1 of K
set end of KN to item 2 of K
end repeat
-- sort the entries in both lists into numerical order
sort_items(KN, KK)
-- find missing values and insert spaces in Key list KK
set missing to {}
repeat with j from 2 to 200 -- limit set high enough to make room for growth of list
try
if (1 + (item (j - 1) of KN)) ≠(item j of KN) then
set m to 1 + (item (j - 1) of KN)
set KN to insertInList(KN, m, j - 1)
set KK to insertInList(KK, missing value, j - 1)
set end of missing to j
end if
on error -- no more values
exit repeat
end try
end repeat
missing (* By list position; one greater than the missing key code (list starts with 0): {11, 53, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 69, 71, 73, 74, 75, 78, 80, 81, 91, 94, 95, 96, 103, 105, 108, 109, 111, 113, 114} *)
KK --> {"aA", "sS", "dD", "fF", "hH", "gG", "zZ", "xX", "cC", "vV", missing value, "bB", "qQ", "wW", "eE", "rR", "yY", "tT", "1!", "2@", "3#", "4$", "6^", "5%", "=+", "9(", "7&", "-_", "8*", "0)", "]}", "oO", "uU", "[{", "iI", "pP", "Return", "lL", "jJ", "'\"", "kK", ";:", "\\|", ",<", "/?", "nN", "mM", ".>", "Tab", "Space", "'~", "Del", missing value, "esc", missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, "N: .", missing value, "N: *", missing value, "N: +", missing value, "clear", missing value, missing value, missing value, "N: /", "Enter", missing value, "N: -", missing value, missing value, "N: =", "N: 0", "N:1", "N: 2", "N: 3", "N: 4", "N: 5", "N: 6", "N: 7", missing value, "N: 8", "N: 9", missing value, missing value, missing value, "F5", "F6", "F7", "F3", "F8", "F9", missing value, "F11", missing value, "F13", "F16", missing value, missing value, "F10", missing value, "F12", missing value, missing value, "Help", "Home", "page up", "Fwd Del", "F4", "end", "F2", "page down", "F1", "left arrow", "right arrow", "down arrow", "up arrow"} KK is now a full list of 127 entries for the integers between 0 and 126 in numerical order. Entries for which there is no corresponding key are missing values.
to sort_items(sortList, SecondList) -- handler by Kai
-- sorts first list and keeps second list in correspondance with first
script L
property srt : sortList
property sec : SecondList
--property thd : thirdList
end script
tell (count L's srt) to repeat with i from (it - 1) to 1 by -1
set s to (L's srt)'s item i
set r to (L's sec)'s item i
--set q to (L's thd)'s item i
repeat with i from (i + 1) to it
tell (L's srt)'s item i to if s > it then
set (L's srt)'s item (i - 1) to it
set (L's sec)'s item (i - 1) to (L's sec)'s item i
--set (L's thd)'s item (i - 1) to (L's thd)'s item i
else
set (L's srt)'s item (i - 1) to s
set (L's sec)'s item (i - 1) to r
--set (L's thd)'s item (i - 1) to q
exit repeat
end if
end repeat
if it is i and s > (L's srt)'s end then
set (L's srt)'s item it to s
set (L's sec)'s item it to r
--set (L's thd)'s item it to q
end if
end repeat
end sort_items
to insertInList(myList, Insertion, AfterNum) -- not mine, but no record of author
if AfterNum ≥ (count of myList) then
set end of myList to Insertion
return myList
end if
tell myList
set frontPart to items 1 thru AfterNum
set backPart to items (AfterNum + 1) thru -1
end tell
set myList to frontPart & Insertion & backPart
return myList
end insertInList
Then, copying the list KK in the script above to a new one yields:
set _Keys to {"aA", "sS", "dD", "fF", "hH", "gG", "zZ", "xX", "cC", "vV", missing value, "bB", "qQ", "wW", "eE", "rR", "yY", "tT", "1!", "2@", "3#", "4$", "6^", "5%", "=+", "9(", "7&", "-_", "8*", "0)", "]}", "oO", "uU", "[{", "iI", "pP", "Return", "lL", "jJ", "'\"", "kK", ";:", "\\|", ",<", "/?", "nN", "mM", ".>", "Tab", "Space", "'~", "Del", missing value, "esc", missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, "N: .", missing value, "N: *", missing value, "N: +", missing value, "clear", missing value, missing value, missing value, "N: /", "Enter", missing value, "N: -", missing value, missing value, "N: =", "N: 0", "N:1", "N: 2", "N: 3", "N: 4", "N: 5", "N: 6", "N: 7", missing value, "N: 8", "N: 9", missing value, missing value, missing value, "F5", "F6", "F7", "F3", "F8", "F9", missing value, "F11", missing value, "F13", "F16", missing value, missing value, "F10", missing value, "F12", missing value, missing value, "Help", "Home", "page up", "Fwd Del", "F4", "end", "F2", "page down", "F1", "left arrow", "right arrow", "down arrow", "up arrow"}
set KC to (text returned of (display dialog "Enter the keyboard code" & return & "(a number between 0 and 126)" default answer "")) as integer
if KC < 0 or KC > 126 then
display dialog "Number out of range"
return
else if item (KC + 1) of _Keys is missing value then
display dialog "There is no key for that code on this keyboard"
else
display dialog "The key cap should say: " & (item (KC + 1) of _Keys)
end if