# Finding of KeyCode on KeyPress Event

**URL:** <https://forum.inductiveautomation.com/t/finding-of-keycode-on-keypress-event/10877>\
**Category:** General Discussion\
**Created:** [December 7, 2015, 3:06am UTC](https://forum.inductiveautomation.com/t/finding-of-keycode-on-keypress-event/10877 "2015-12-07T03:06:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![suhasghawale](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@suhasghawale](https://forum.inductiveautomation.com/u/suhasghawale)\
**Post date:** [December 7, 2015, 3:06am UTC](https://forum.inductiveautomation.com/t/finding-of-keycode-on-keypress-event/10877/1 "2015-12-07T03:06:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [December 7, 2015, 6:24am UTC](https://forum.inductiveautomation.com/t/finding-of-keycode-on-keypress-event/10877/2 "2015-12-07T06:24:34Z")

</div>

Hello,

You should use the predefined constants defined here: [http://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyEvent.html](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,

---

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [April 30, 2020, 8:44pm UTC](https://forum.inductiveautomation.com/t/finding-of-keycode-on-keypress-event/10877/3 "2020-04-30T20:44:11Z")

</div>

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** :

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

```

---

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [April 30, 2020, 8:45pm UTC](https://forum.inductiveautomation.com/t/finding-of-keycode-on-keypress-event/10877/4 "2020-04-30T20:45:08Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/07d136f1d98f1e813ab4a9560551f26f054f7d62.png)

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [April 30, 2020, 10:01pm UTC](https://forum.inductiveautomation.com/t/finding-of-keycode-on-keypress-event/10877/5 "2020-04-30T22:01:36Z")

</div>

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

```

You missed a bit

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [April 30, 2020, 10:13pm UTC](https://forum.inductiveautomation.com/t/finding-of-keycode-on-keypress-event/10877/6 "2020-04-30T22:13:55Z")

</div>

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:

```auto
if event.keyCode == event.VK_ENTER:
	system.gui.messageBox("Test")

```

---

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [May 1, 2020, 2:45am UTC](https://forum.inductiveautomation.com/t/finding-of-keycode-on-keypress-event/10877/7 "2020-05-01T02:45:56Z")

</div>

Thank you very much!!
