Check state of Option-Key in SwiftUI (macOS)
问题 I'm looking for a way to check the state of the option-key in SwiftUI on macOS. I.e. depending on whether the option key is pressed or not I want to perform different actions in the .onTapGesture closure. 回答1: macOS-only SwiftUI has .modifiers modifier to specify EventModifiers , so your case is covered like in below example: Rectangle() .fill(Color.yellow) .frame(width: 100, height: 40) .gesture(TapGesture().modifiers(.option).onEnded { print("Do anyting on OPTION+CLICK") }) .onTapGesture {