Copy link to clipboard
Copied
There is a function CSInterface.registerKeyEventsInterest which according to the description allows to intercept keypresses globally. The problem is that I can't figure out how to attach a listener to the passed keys and the documentation doesn't tell how to do it. Is there any example of how to use this function to intercept pressed keys?
Copy link to clipboard
Copied
This method is working only in HTML panels. Basically gives the keypress to the embedded chromium instead of PS. From that point You can listen to the key event.
Copy link to clipboard
Copied
I'm trying the following code and it doesn't work (38 - arrow up, 40 - arrow down, 13 - enter). That is the bound listeners aren't triggered. Sorry for code formatting...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="CSInterface.js"></script>
<script>
var csi = new CSInterface();
csi.registerKeyEventsInterest([
{ keyCode: 38 },
{ keyCode: 40 },
{ keyCode: 13 }
]);
window.addEventListener('keydown', function() {
console.log('keydown');
});
window.addEventListener('keypress', function() {
console.log('keypress')
});
window.addEventListener('keyup', function() {
console.log('keyup');
})
</script>
</head>
<body>
</body>
</html>
Copy link to clipboard
Copied
It requires a JSON string.
var csi = new CSInterface();
csi.registerKeyEventsInterest( JSON.stringify( [
{ keyCode: 38 },
{ keyCode: 40 },
{ keyCode: 13 }
]));
Copy link to clipboard
Copied
It doesn't work on my machine for some reason Does this code work for you?
Copy link to clipboard
Copied
Maybe the keyCodes aren't right. Try to console.log them out before registering them. They are "Virtual KeyCodes" or something.
Copy link to clipboard
Copied
For me it even says this "registerKeyEventsInterest" is not a function.