Skip to main content
Participant
May 13, 2017
Question

CSInterface.registerKeyEventsInterest

  • May 13, 2017
  • 1 reply
  • 2230 views

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?

This topic has been closed for replies.

1 reply

oliverIntergrafika
Inspiring
May 13, 2017

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.

KeyboardEvent - Web APIs | MDN

Participant
May 13, 2017

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>

Participant
May 14, 2017

It requires a JSON string.

var csi = new CSInterface();
  csi.registerKeyEventsInterest( JSON.stringify( [
  { keyCode: 38 },
  { keyCode: 40 },
  { keyCode: 13 }
  ]));


It doesn't work on my machine for some reason Does this code work for you?