optionKeyDown message broken

Paul Dupuis paul at researchware.com
Thu Apr 21 16:19:50 EDT 2022


On 4/21/2022 3:27 PM, J. Landman Gay via use-livecode wrote:
> On 4/21/22 10:55 AM, Paul Dupuis via use-livecode wrote:
>> In a new stack, place the following in the card script:
>>
>> on optionKeyDown pKeyName
>>    if platform() = "MacOS" then
>>      put numToChar(charToNum(pKeyName)-128) into tKey1 -- original 
>> sample from Dictionary
>>      put numToCodePoint(codepointToNum(pKeyName)-128) into tKey2 -- 
>> trying using non-deprecated functions
>>      answer pKeyName,tKey1,tKey2
>>    else -- windows
>>      answer pKeyName
>>    end if
>> end optionKeyDown
>
> The equivalent new functions for numToChar and charToNum is 
> numToNativeChar and nativeCharToNum. Those return the same values as 
> the originals. However, I'm still getting the wrong result. I can 
> subtract 94 to get lower-case "f" but that isn't consistent; the 
> amount to subtract varies depending on the value of pKeyName. So 
> there's some trick I'm missing.
>
> Tested on Mac.
>

Thank you for verifying macOS!

I did not know about numToNativeChar and nativeCharToNum so thanks for 
that also. However, after looking at a decimal table of MacRoman, the 
suggested formula to remove the "high-bit" in the Dictionary will NEVER 
work no matter what functions are used. The high-ASCII characters of 
MAcROman (bytes 128 to 255) do not correspond to any alphabetical range. 
In other words, the numerical equivalent of OPTION-A through OPTION-Z is 
not in sequential order.

You would either have to code it as:

on optionDownKey pKey
   if platform() = "MacOS" then
     if pKey = "ƒ" then put "f" in tKey -- MacRoman byte 196 (OPTION-F 
is pressed)
     if pKey = "≈" then put "x" in tKey -- MacRoman byte 197 (is NOT 
OPTION-G (expected if in alphabetical order and you could just do math 
to get the ASCII key character), but is OPTION-X)

In my opinion, this makes the optionKeyDown handler on macOS next to 
useless and it is far more intuitive from a develop and code 
documentation perspective if the letter of the key pressed in 
conjunction with the OPTOPN key was returned.

And, of course, you can work around this with a rawKeyDown or rawKeyUp 
handler, but I would consider the state of optionKeyDown on macOS defective.





More information about the use-livecode mailing list