1
2

More than 1 year has passed since last update.

【SwiftUI・KeyboardShortcut】外部キーボードの入力検知一覧

Posted at

KeyboardShortcut

外部キーボードの検知を伝えるには .keyboardShortcut(, modifiers: []) を使用して、Buttonなどに通知することができます。

Button {
// ボタン押下時の処理
} label: {
// ラベル(ButtonにするView)を記述
}.keyboardShortcut(押下するボタン, modifiers: [])

KeyboardShortcutの一覧

SwiftUIで外部キーボードのボタンごとの入力の検知をまとめてみました。

文字

.keyboardShortcut("J" , modifiers: [])
.keyboardShortcut("6" , modifiers: [])

文字が変数に含まれている場合

var character = "J"
var array = ["A","B","C"]
///////////////////////
.keyboardShortcut(KeyEquivalent(Character(character)), modifiers: [])
///////////////////////
.keyboardShortcut(KeyEquivalent(Character(array[0])), modifiers: [])

upArrow

.keyboardShortcut(.upArrow , modifiers: [])

downArrow

.keyboardShortcut(.downArrow , modifiers: [])

leftArrow

.keyboardShortcut(.leftArrow , modifiers: [])

rightArrow

.keyboardShortcut(.rightArrow , modifiers: [])

clear

.keyboardShortcut(.clear , modifiers: [])

delete

.keyboardShortcut(.delete , modifiers: [])

deleteForward

.keyboardShortcut(.deleteForward , modifiers: [])

end

.keyboardShortcut(.end , modifiers: [])

escape

.keyboardShortcut(.escape , modifiers: [])

home

.keyboardShortcut(.home , modifiers: [])

pageDown

.keyboardShortcut(.pageDown , modifiers: [])

pageUp

.keyboardShortcut(.pageUp, modifiers: [])

return

.keyboardShortcut(.return , modifiers: [])

space

.keyboardShortcut(.space, modifiers: [])

tab

.keyboardShortcut(.tab, modifiers: [])

参考

https://developer.apple.com/documentation/swiftui/keyequivalent
https://stackoverflow.com/questions/64916392/how-to-enable-the-delete-key-shortcut-in-the-edit-menu-of-a-swiftui-app-on-macos

1
2
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
1
2