use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
# A delay allowing you to press one or several modifiers
delay 2
set optionDown to my checkModifier:"option"
say "optionDown is " & optionDown
set shiftKeyDown to my checkModifier:"shift"
say "shiftKeyDown is " & shiftKeyDown
set commandKeyDown to my checkModifier:"command"
say "commandKeyDown is " & commandKeyDown
set controlKeyDown to my checkModifier:"control"
say "controlKeyDown is " & controlKeyDown
on checkModifier:keyName
if keyName = "option" then
set theMask to current application's NSAlternateKeyMask as integer
else if keyName = "control" then
set theMask to current application's NSControlKeyMask as integer
else if keyName = "command" then
set theMask to current application's NSCommandKeyMask as integer
else if keyName = "shift" then
set theMask to current application's NSShiftKeyMask as integer
else
return false
end if
set theFlag to current application's NSEvent's modifierFlags() as integer
return (((theFlag div theMask) mod 2) = 1)
end checkModifier: