Is it possible to read individual keystrokes in a TextField?

I know how to get the complete text of what the user entered, but is it possible to detect each keystroke before the exit that field?

Replies

I'm sure there's an easier way, but you could get the difference between the previous value and the current value in the onEditingChanged event.

hi,


EDIT: OOPS - missed that this is a SwiftUI question (and i'm not there yet), so not sure if the following really answers the question ⚠


you might want to go back to the topic "Understanding UITextView Input" of May 10 and using the shouldChangeText(in:replacementText:) method (part of UITextInput protocol that UITextField conforms to).


in short, shouldChangeText(in:replacementText:) gives you a more general way to see what's coming into a UITextField before it gets there (which could be from a keystroke, but also from a paste); it may do what you need, but i don't know that there's a direct keystroke reader (assume you're talking about iOS).


hope that helps,

DMG