Tracktion / choc

A collection of header only classes, permissively licensed, to provide basic useful tasks with the bare-minimum of dependencies.
Other
543 stars 49 forks source link

(macOS) Webview can't capture arrow keys with `performKeyEquivalent` registered #56

Closed awood314 closed 3 months ago

awood314 commented 3 months ago

Hi,

I've found that on macOS, apps running in the Webview do not receive some keydown events, specifically for arrow keys (and possibly some others).

I noticed that the performKeyEquivalent hook implemented here does get triggered for arrow keys: https://github.com/splice/choc/blob/ff55347f1cc20b915e87a6d88c777b82e3675084/gui/choc_WebView.h#L797

Regardless of what it returns in this handler, arrow key events are not propagated to the web application. However, removing the registration entirely does fix the issue.

I'm not sure exactly why this is happening. The docs for performKeyEquivalent seem to suggest that the handler might need to invoke super.

If the view’s key equivalent is the same as the characters of the key-down event theEvent, as returned by charactersIgnoringModifiers, the view should take the appropriate action and return true. Otherwise, it should return the result of invoking super’s implementation.

However, I tried this by usingobjc_msgSendSuper to send performKeyEquivalent: to the NSView super class, and still can't receive arrow key events from within the Webview

awood314 commented 3 months ago

separately, it would be nice to have some config that disables these copy commands entirely (for reference: https://github.com/splice/choc/pull/7)

This could also disable accelerator key commands Windows, since they can allow for some funny things like opening printer dialogs...

julianstorer commented 3 months ago

I didn't see that problem myself, but you're right about calling the superclass, so I've added that, and pushed to the develop branch. Let me know if it still gives you any trouble