Created
July 27, 2019 16:43
-
-
Save mooz/4ff1cada781c1426e93283870fb8e1ac to your computer and use it in GitHub Desktop.
Capture ctlr-space in iPadOS public beta 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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