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

ScriptUI.environment.keyboardState.keyName is returning undefined in Windows

Explorer ,
Jul 08, 2020 Jul 08, 2020

Copy link to clipboard

Copied

I have a script that checks the state of Esc key to abort it.

So I'm using ScriptUI.environment.keyboardState.keyName to check if the esc is pressed.
It works like a charm in MacOs.

But for some reason in Windows it is returning undefined, no metter which key I press.

Does any one have a hint what could be wrong?

 

* All the other properties from ScriptUI.environment.keyboardState (like shiftKey) works fine in Windows.

 

EDIT:

Finally found out the problem!

It is related to the keyboard layout.

If I open Indesign with US keyboard layout it works fine, if I use Japanese keyboard layout It dont works, even if I set the input to Roman alphabet.

 

EDIT2:

I found out the problem, but not the solution.

TOPICS
Bug , How to , Scripting

Views

1.1K

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

correct answers 1 Correct answer

Explorer , Jul 10, 2020 Jul 10, 2020

Finally found out the problem!

It is related to the keyboard layout.

If I open Indesign with US keyboard layout it works fine, if I use Japanese keyboard layout It dont works, even if I set the input to Roman alphabet.

Votes

Translate

Translate
Community Expert ,
Jul 09, 2020 Jul 09, 2020

Copy link to clipboard

Copied

Not sure if this is related. To check which key was pressed I use an defiiferent than what you use. The script below I use (on Windows) to check the names and identifiers of keys:

w = new Window ('dialog');
  w.edit = w.add ('edittext {characters: 5, active: true}');
    w.addEventListener ('keydown', function (kd) {pressed (kd)});
    function pressed (k) {
      $.writeln (k.keyName);
      $.writeln (k.keyIdentifier);
    }
w.show();

keyName is a string like PageUp, Home, or Esc. keyIdentifier is either the same string or a Unicode index. It so happens that the keyName of Esc is 'Esc' and its keyIdentifier is 'undefined'. As far as I know, Pause and Del are the only other keys with an undefined identifier.

 

Again, I'm not sure if this is related to your problem. But when you use an event listener as set out in the code snippet here, you can catch the Esc key.

 

P.

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
Explorer ,
Jul 09, 2020 Jul 09, 2020

Copy link to clipboard

Copied

Hello Peter, thank you very much for the response.

Your snippet worked fine, but I cannot use it as a workaround once I need verify the key state while my script is running.

 

Sorry to ask you, but could you try to run this and check if it is returning the keys?

while(!ScriptUI.environment.keyboardState.shiftKey) {
	alert(ScriptUI.environment.keyboardState.keyName);
}
I'm suspecting it can maybe a bug in the Japanese version of Indesign.
 
 
Best regards
Alan

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 Expert ,
Jul 09, 2020 Jul 09, 2020

Copy link to clipboard

Copied

Hi Alan,

on Windows 10 I found that keyboardState is NOT registered when you run the code from the ExtendScript Toolkit app.

Run your code from a script file from the Scripts panel in InDesign.

 

Did not test your code but a similar one:

https://community.adobe.com/t5/indesign/press-escape-to-stop-the-script/m-p/10980089#M178962

 

Regards,
Uwe Laubender

( ACP )

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
Explorer ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

Hello Laubender, thank you very much, but unfortunatelly it is not my case.

I'm running it from the script menu, the keyboardState is working fine except for the keyName property

 

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
Explorer ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

Finally found out the problem!

It is related to the keyboard layout.

If I open Indesign with US keyboard layout it works fine, if I use Japanese keyboard layout It dont works, even if I set the input to Roman alphabet.

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 Expert ,
Aug 06, 2020 Aug 06, 2020

Copy link to clipboard

Copied

LATEST

Good to know. Thanks for the information.

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