There are several problems that come up when applying this technique on Tiger.
The first one (the one you ran into) is that characters outside of the system’s primary encoding (usually MacRoman) are not directly usable in the text of an AppleScript program. There is a workaround for representing Unicode characters that are not a part of the primary encoding’s repertoire: set shiftSymbol to («data utxt21E7» as Unicode text). The 21E7 are the two hex bytes for the shift symbol’s UTF-16BE encoding. This stores in shiftSymbol a value similar to what would have been stored using set shiftSymbol to “â‡§” on Leopard.
The next issue that you will find is that the UI elements that represent the keys in Tiger’s KeyboardViewerServer are not checkboxes, but buttons. Worse, there seems to be no way of sensing the darkened/normal status of these buttons via the accessibility API.
If you know that Command and Control will never be pressed while you make your key check, you could rig up something like
name of UI element "A"
return true if result is "A"
And something similar for “Ã…” to catch when Option is being used with/without Shift. There would have to be some extra error handling since when Option is down UI element “A” will throw an error. Correspondingly, when Option is up, UI element “Ã…” will throw an error.
The problem with Control is that it completely blanks out the “A” button, so neither named UI element will exist (this would cause both UI element reference forms to throw errors). The problem with Command is that it causes the “A” button to always show “a”, even when used with Shift (this would cause a false negative, Shift might be down but the “A” key will still say “a”).
Oh yeah, and there is the problem of Caps Lock when testing an alphabetic character. I nearly forgot about that since I always remap it to be another Control key (feature introduced in Tiger).
I put something together, but it just seems too unreliable to bother posting. It will also probably have problems for non-English keyboards and/or key layouts (“A” seems fairly universal, but I bet some do not have “A”, and many more do not use “Ã…” as the alternate character).
I know that Extra Suites can tell you if Shift is down, but I think I have heard that it may not work on Intel Macs. Otherwise, it should be possible to make a command-line tool that could relay the keyboard modifier status (maybe one already exists?).
Model: iBook G4 933
Browser: Safari 4 Public Beta (4528.17)
Operating System: Mac OS X (10.4)