¿AppleScript para verificar si la tecla fn está presionada?

¿Cómo puedo devolver 1 cuando fnestá presionado y 0 en caso contrario?

Encontré esta página que afirma tener una solución, pero se basa en un archivo de script de shell externo (preferiría tener una solución pura de AppleScript si eso es posible) que no puedo descargar porque me redirige a través de algunos extraños sitios de estafas holandeses.

El objetivo de esto es en realidad tener una forma de verificar las combinaciones de tecla de función + tecla fn en ControllerMate, que no parece tener una forma de verificar si se presiona fn o no.

Respuestas (1)

Directamente del post de Oscar ...

property vers : "1.0"
my isModifierKeyPressed("function") // the only addition to his raw script

on isModifierKeyPressed(checkKey)
    set modiferKeysDOWN to {command_down:false, option_down:false, control_down:false, shift_down:false, caps_down:false, numlock_down:false, function_down:false}

    if checkKey = "" or checkKey = "option" or checkKey = "alt" then
        if (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSAlternateKeyMask '") > 1 then
            set option_down of modiferKeysDOWN to true
        end if
    end if

    if checkKey = "" or checkKey = "command" then
        if (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSCommandKeyMask '") > 1 then
            set command_down of modiferKeysDOWN to true
        end if
    end if

    if checkKey = "" or checkKey = "shift" then
        if (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSShiftKeyMask '") > 1 then
            set shift_down of modiferKeysDOWN to true
        end if
    end if

    if checkKey = "" or checkKey = "control" then
        if (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSControlKeyMask '") > 1 then
            set control_down of modiferKeysDOWN to true
        end if
    end if

    if checkKey = "" or checkKey = "caps" or checkKey = "capslock" then
        if (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSAlphaShiftKeyMask '") > 1 then
            set caps_down of modiferKeysDOWN to true
        end if
    end if

    if checkKey = "" or checkKey = "numlock" then
        if (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSNumericPadKeyMask'") > 1 then
            set numlock_down of modiferKeysDOWN to true
        end if
    end if
    --Set if any key in the numeric keypad is pressed. The numeric keypad is generally on the right side of the keyboard. This is also set if any of the arrow keys are pressed

    if checkKey = "" or checkKey = "function" or checkKey = "func" or checkKey = "fn" then
        if (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSFunctionKeyMask'") > 1 then
            set function_down of modiferKeysDOWN to true
        end if
    end if
    --Set if any function key is pressed. The function keys include the F keys at the top of most keyboards (F1, F2, and so on) and the navigation keys in the center of most keyboards (Help, Forward Delete, Home, End, Page Up, Page Down, and the arrow keys)

    return modiferKeysDOWN
end isModifierKeyPressed

si Fn está abajo

Result:  
{command_down:false, option_down:false, control_down:false, shift_down:false, caps_down:false, numlock_down:false, function_down:true}

demás

Result:  
{command_down:false, option_down:false, control_down:false, shift_down:false, caps_down:false, numlock_down:false, function_down:false}
Eso no funciona para mí porque si el usuario mantiene presionada la tecla F1, por ejemplo, todavía se informa como verdadero.
Solo una actualización para decir que más abajo en el mismo hilo hay una versión de la misma rutina que no usa php. Esto es importante ya que macOS 12 ahora ha depreciado php.