3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Cocoaの機能を使ってMacで押下されている装飾キーを取得するAppleScriptハンドラ

Posted at
  • ハンドラ呼び出し時に押下されている装飾キーを取得
    • System Eventsの予約語を使用して、次の4種類のキーをリストで返す
      • shift down
      • control down
      • option down
      • command down
  • repeat行のリストを変更すればCaps Lockなど他のキー状況も取得可能
enteredModifiers.scpt
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クラスを使って作成
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?