• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CSInterface.registerKeyEventsInterest

Community Beginner ,
May 13, 2017 May 13, 2017

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?

TOPICS
Actions and scripting

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Contributor ,
May 13, 2017 May 13, 2017

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.

KeyboardEvent - Web APIs | MDN

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 13, 2017 May 13, 2017

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 13, 2017 May 13, 2017

Copy link to clipboard

Copied

It requires a JSON string.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 14, 2017 May 14, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 14, 2017 May 14, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 31, 2018 Oct 31, 2018

Copy link to clipboard

Copied

LATEST

For me it even says this "registerKeyEventsInterest" is not a function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines