Posted at


More than 3 years have passed since last update.

  • ハンドラ呼び出し時に押下されている装飾キーを取得

    • System Eventsの予約語を使用して、次の4種類のキーをリストで返す

      • shift down

      • control down

      • option down

      • command down

  • repeat行のリストを変更すればCaps Lockなど他のキー状況も取得可能


use scripting additions

use framework "AppKit"

delay 3 --この間に装飾キーを押下
my enteredModifiers()
--> {shift down, control down, option down, command down}

on enteredModifiers()
--require framework: AppKit
set modifierFlags to current application's NSEvent's modifierFlags()
set modifierList to {}
repeat with flag in {{modifierName:shift down, keyMask:current application's NSShiftKeyMask}, {modifierName:control down, keyMask:current application's NSControlKeyMask}, {modifierName:option down, keyMask:current application's NSAlternateKeyMask}, {modifierName:command down, keyMask:current application's NSCommandKeyMask}}
if modifierFlags div (keyMask of flag as integer) mod 2 = 1 then
set end of modifierList to modifierName of flag
end if
end repeat
return modifierList
end enteredModifiers


  • 2016-10-05: AppKitフレームワークのNSEventクラスを使って作成