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

eventListner ( ENTER / RETURN ) and MouseScrollButton on Script?

Participant ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

Aloha insane coders.

I am finalizing an interface and would like to know if it is possible to add an eventListner so that by pressing the "Enter / Return" button the action of the button is also executed. This makes the use of the interface more intuitive. Every time I try to intuitively do this ... when I test the interface.

Another question is if I can put an event listner in the area of a panel where the content is controlled by a scrollbar. When I use the mouse scrollbutton on top of the scrollbar the button works, but I would like to be able to add an eventlistner when the mouse is over the content too, plus the scrollbar is very slow when using the mouse scrollbutton.

I am not finding any documentation about it.

Thanks in advance for your support ...

Rubens

TOPICS
Scripting

Views

1.4K

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 , May 15, 2018 May 15, 2018

Two options regarding the Enter Button:

Easiest solution: If you just assign "name: ok" - this will execute the button on enter by default. 

var myButton = pal.add("button", undefined, "Enter", {name: "ok"});

If you want to use the event listener: This only works, if the button is active. You can do this via an event listener and doing the false / true trick.

function handle_key(key, control){

  switch (key.keyName)

  {

    case "Enter":

      key.preventDefault();

      // do stuff

      break;

    defau

...

Votes

Translate

Translate
New Here ,
Apr 24, 2018 Apr 24, 2018

Copy link to clipboard

Copied

Here is hopefully a start for the keydown event listener.

w.addEventListener ("keydown", keyPressHandler);  // Add event "keydown" to whatever and have it call a function

function keyPressHandler (ev){  // ev contains information sent by the EventListener
    if(ev.type == "keydown" && ev.keyName == "Enter"){
        p.preventDefault(); // If I have this right, this makes sure that the event is only executed once
        // Add whatever you want to happen here
    }
}

I'm not sure about the scrollbar.  I'm pretty sure extendscript does not listen for direction of the scroll wheel.  It can tell it's moving but not in what directions, which is pretty useless imo.  If I'm wrong about that I would love to know because the scroll wheel could be super useful in UI stuff.

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
Participant ,
May 15, 2018 May 15, 2018

Copy link to clipboard

Copied

Hey Dash... thanks for your help, but this addEventListner is not working for me.

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 ,
May 15, 2018 May 15, 2018

Copy link to clipboard

Copied

Two options regarding the Enter Button:

Easiest solution: If you just assign "name: ok" - this will execute the button on enter by default. 

var myButton = pal.add("button", undefined, "Enter", {name: "ok"});

If you want to use the event listener: This only works, if the button is active. You can do this via an event listener and doing the false / true trick.

function handle_key(key, control){

  switch (key.keyName)

  {

    case "Enter":

      key.preventDefault();

      // do stuff

      break;

    default:

      return;

  }

}

var mouseEventHandler = function(ev){

  if(ev.type == 'mouseover'){

    myButton.active = false;

    myButton.active = true;

  }

}

myButton.addEventListener('mouseover', mouseEventHandler);

myButton.addEventListener("keydown", function(k){handle_key(k, this);});

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
Participant ,
May 15, 2018 May 15, 2018

Copy link to clipboard

Copied

Thank you so much, ILJI

It's Working Now, but I have to put the event listener into the editText the user is forced to fill.

As I'm using an iconButton this still not working, I don't know why.
If you have a solution to iconButtons with multiple image instances. I would love to hear.

Cheers.

Rubens Nobre.

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 ,
May 15, 2018 May 15, 2018

Copy link to clipboard

Copied

LATEST

Okay, when you have the listeners on the editText now, the "enter" will trigger your defined action. What do you need now exactly - to have the button react to pressing "enter", even if the editText is not active? For this case, you would just need to make sure that some other (or all) object gets activated on mouseover or mousemove and have that object have the key event listener applied to as well. The stuff which happens, when hitting enter could also change the button state/button image, if that is what you are aiming for.

Cheers.

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