79537365

Date: 2025-03-26 22:07:42
Score: 1.5
Natty:
Report link

With WKWebView's, the keyboard functionality is limited much more than on a textfield but you do have options depending on what you are wanting to modify.

Preventing keyboards and text interaction:

NotificationCenter.default.addObserver(
    forName: UIResponder.keyboardWillShowNotification,
    object: nil,
    queue: OperationQueue.main
) { [weak self] _ in
    Task { @MainActor [weak self] in
        self?.webView.endEditing(true)
    }
}

Prevent specific input characters:

document.body.addEventListener('keydown', function(e) {
    if (e.key === " " || e.keyCode === 32) {
        e.preventDefault();

        return;
    }
});

Modifying the keyboard type(ish):

To have full control over a WKWebView's keyboard, creating a custom keyboard is probably the best solution but its more inconvenient. However, if you just need to modify specific behaviors or settings, I hope the solutions I suggested above help!

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Whitelisted phrase (-1.5): you can use
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • User mentioned (1): @already
  • Looks like a comment (1):
  • Low reputation (1):
Posted by: Liam Gleeson