Finding of KeyCode on KeyPress Event

Can anyone explain me how to find out keyCode on keypress event of TextBox component?
I am trying to find out enter button keyCode when enter key get pressed in the TextBox component.

Hello,

You should use the predefined constants defined here: http://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyEvent.html

For example, catching the enter key:from java.awt.event import KeyEvent if event.keyCode == KeyEvent.VK_ENTER: print "yep"Best,

1 Like

Based on your code, I want to print “yep” when I press the “Enter” Key on a Text Field.
I wrote this code on the PropertyChange Event Script of this Text Field component.
I used the following code, per your recommendation but it gives me an error:

import KeyEvent
if event.keyCode == KeyEvent.VK_ENTER: 
   print "yep"

image

from java.awt.event import KeyEvent 
if event.keyCode == KeyEvent.VK_ENTER: print "yep"

You missed a bit

2 Likes

You are probably already aware but just in case… print is for the script editor etc not a client

Put this in a key pressed event in your component:

if event.keyCode == event.VK_ENTER:
	system.gui.messageBox("Test")
1 Like

Thank you very much!!

1 Like