Run Button On Click Script When Key is Pressed


Is it possible to run a button's on click event when the 'Enter' key is pressed? The on click event is a navigation script with one url parameter. I noticed that within Session Events there is a key events section, but I am not sure as to how to specify the specific view to act on and how I would access the view params to pass the value. What would be the best way of identifying when the 'Enter' key is pressed and running the navigation script?

Put the logic of the button into a project script, and then you can call it on any event (button press, key press, etc) with ease. It's fine to need parameters for your function to work correctly if that is what is required.

If you need help refactoring, post your button's current script.

Sorry maybe I should've been more clear in my post, but I feel that my main problem is how I should be identifying if the 'Enter' button is pressed as the script is simple a navigate.

The keyCode should be 10 I believe. You can do a system.perpective.print(theKeyCodeVariableHere) to confirm that.

I tried checking if the keyCode was 10 and checking for "VK_ENTER", but both did not work. I tried printing out event.keyCode but it returned 0 no matter what button I pressed. It is also worth noting that keyCode is deprecated.

What do you see for the key (str) value when you press enter?

It's blank but I'm assuming it is entering a '\n'.

Get rid of the button, and move your navigation script to the onActionPerformed event on the numeric entry field. When you hit enter, it will trigger the action performed event.


The input is a text field. I also can't change it to a numeric entry field as some employee numbers contain alphanumeric characters.

On the text field, use onKeyPress and add this script with your nav info filled in.

if event.charCode == 13:
	empNumb = self.props.text
	system.perspective.navigate(page, url, view, params, newTab)
1 Like

Thanks I got it working!