# Key-pressed code not working

**URL:** <https://forum.inductiveautomation.com/t/key-pressed-code-not-working/15958>\
**Category:** Ignition\
**Created:** [November 10, 2017, 7:57am UTC](https://forum.inductiveautomation.com/t/key-pressed-code-not-working/15958 "2017-11-10T07:57:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kleppe85](https://avatars.discourse-cdn.com/v4/letter/k/c4cdca/32.png) [@Kleppe85](https://forum.inductiveautomation.com/u/Kleppe85)\
**Post date:** [November 10, 2017, 7:57am UTC](https://forum.inductiveautomation.com/t/key-pressed-code-not-working/15958/1 "2017-11-10T07:57:58Z")

</div>

Hi,  
I’m having some strange behavior in my application.  
I have created a custom login screen, with key-pressed event for TAB and Enter key.  
This works fine as long as I have the menu-bar and window menu activated in the client.  
But if I disable these, none of the key-pressed events are working.

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

Running Windows 7 and Ignition 7.9.4

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 10, 2017, 1:33pm UTC](https://forum.inductiveautomation.com/t/key-pressed-code-not-working/15958/2 "2017-11-10T13:33:33Z")

</div>

Key-pressed events only go to the component that has the focus. When the menu is active, the window itself has the focus, so you get the events on the window.  
What you really want is a [key binding](https://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html), which I believe you’ll have to construct and activate manually. Good luck!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 10, 2017, 4:24pm UTC](https://forum.inductiveautomation.com/t/key-pressed-code-not-working/15958/3 "2017-11-10T16:24:04Z")

</div>

Complicating things further, I’m pretty sure tab and enter are both treated differently by swing because they’re part of the focus traversal system - so you’ll probably have to remove their default actions, then implement Phil’s suggestion.

---

<div class="post-metadata">

**Author:** ![samngeru](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/samngeru/32/6007_2.png) [@samngeru](https://forum.inductiveautomation.com/u/samngeru)\
**Post date:** [November 11, 2017, 4:21am UTC](https://forum.inductiveautomation.com/t/key-pressed-code-not-working/15958/4 "2017-11-11T04:21:42Z")

</div>

Don’t know if this will work for you but you can try requesting focus for some component on that screen and then continue with your key pressed event. Script below is on the internalFrameActivated event of a window.

```auto
component = system.gui.getParentWindow(event).getComponentForPath('Root Container.Button')
component.requestFocusInWindow()

```
