this post was submitted on 05 Sep 2025
1 points (100.0% liked)

Swift

554 readers
1 users here now

This group focus on the content related to the development of Apple Eco-system software. So feel free to share and talk about, for example;

founded 3 years ago
MODERATORS
 

So I have a view that is focusable and has onKeyPress on it. I want to show a modal dialog when the user presses the delete key. However, it seems that the pressedKey.key for the delete key does not equal KeyEquivalent.delete value.

Example:

import SwiftUI

struct MyView: View {
    var body: some View {
        Rectangle()
            .frame(width: 100, height: 100)
            .focusable()
            .focusEffectDisabled()
            .onKeyPress { pressedKey in
                // Output: KeyEquivalent(character: "\u{7F}") == KeyEquivalent(character: "\u{08}")            
                print("\(pressedKey.key) == \(KeyEquivalent.delete)")
                return .handled
            }
    }
}

Am I missing something that is otherwise obvious?

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here