Skip to main content
Inspiring
July 9, 2020
Answered

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

  • July 9, 2020
  • 3 replies
  • 1752 views

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.

This topic has been closed for replies.
Correct answer AlanOliveira89

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.

3 replies

AlanOliveira89AuthorCorrect answer
Inspiring
July 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.

Adobe Expert
August 7, 2020

Good to know. Thanks for the information.

Adobe Expert
July 9, 2020

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 )

Inspiring
July 10, 2020

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

 

Adobe Expert
July 9, 2020

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.

Inspiring
July 9, 2020

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