Skip to content

Instantly share code, notes, and snippets.

@mooz
Created July 27, 2019 16:43
Show Gist options
  • Save mooz/4ff1cada781c1426e93283870fb8e1ac to your computer and use it in GitHub Desktop.
Save mooz/4ff1cada781c1426e93283870fb8e1ac to your computer and use it in GitHub Desktop.
Capture ctlr-space in iPadOS public beta 3
let ctrlKey = false;
// Workaround for capturing Ctrl-Space
$define({
type: "WKWebView",
events: {
// Swizzling handleKeyUIEvent doesn't work. We need to swizzle the private one (_handleXXX).
"_handleKeyUIEvent:": evt => {
const CTRL = 224;
const SPACE = 44;
let keyCode = evt.$__keyCode();
let pressed = evt.$__isKeyDown();
if (keyCode === CTRL) {
if (pressed) {
ctrlKey = true;
} else {
ctrlKey = false;
}
} else if (keyCode === SPACE) {
// Space key.
if (ctrlKey) {
if (pressed) {
// Ctrl + Space. Prevent default action by returning null.
// Call
CALL_SOME_METHOD_IF_YOU_WANT();
}
return null;
}
}
return self.$ORIG__handleKeyUIEvent(evt);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment