# Removing Focus in a Window

**URL:** <https://forum.inductiveautomation.com/t/removing-focus-in-a-window/28059>\
**Category:** Ignition\
**Created:** [September 5, 2019, 9:59pm UTC](https://forum.inductiveautomation.com/t/removing-focus-in-a-window/28059 "2019-09-05T21:59:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [September 5, 2019, 9:59pm UTC](https://forum.inductiveautomation.com/t/removing-focus-in-a-window/28059/1 "2019-09-05T21:59:03Z")

</div>

I’m having a lot of fun trying to get Client Keystroke Event Scripts to be the entities that capture Left & Right Arrow Key Presses. It seems like almost everything consumes those before the Client Event system gets to them. In my window there is a slider that the operator used to set motor speed. The motor drives a pump and the system controls the flow by opening and closing analog check valves. The Left/Right arrow keys are supposed to control these check valve positions. Unfortunately once the operator adjusts the speed the slider has focus and consumes the arrow button presses.

If the arrow keys are pressed right after the window is loaded they work as desired.

In an effort to figure out what to give focus to after the motor speed was set I added the following code to my internalFrameActivated event script for the window:

```auto
from java.awt import KeyboardFocusManager
focusedComponent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()
print focusedComponent.getName()

```

After adding this and navigating to the window the console output for the component name was “None”.  
At a point I saved, published, updated again while still on this window and the component name was different. It was actually the project name.

So the question, is there a way to set the focus to NOTHING (remove it from all screen components)?  
What about setting it to the project itself?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 6, 2019, 12:26pm UTC](https://forum.inductiveautomation.com/t/removing-focus-in-a-window/28059/2 "2019-09-06T12:26:29Z")

</div>

I’m a total noob with java, but this link for [no focus button](http://www.java2s.com/Tutorial/Java/0260__Swing-Event/NoFocusButton.htm) seems to maybe offer a clue?  
**EDIT**  
I actually found this and it does work on removing focus. Just put it in an appropriate event handler.

```auto
event.source.setFocusable(0)

```

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [September 6, 2019, 1:16pm UTC](https://forum.inductiveautomation.com/t/removing-focus-in-a-window/28059/3 "2019-09-06T13:16:47Z")

</div>

Hey dkhayes,

I tried that, but it just moves the focus to the next item in the focus order.  
In my case that is a button and it seems that buttons consume the left/right arrow key pressed events, so it isn’t a fix for my issue.

I appreciate the help though!

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 6, 2019, 1:32pm UTC](https://forum.inductiveautomation.com/t/removing-focus-in-a-window/28059/4 "2019-09-06T13:32:29Z")

</div>

> [@Setting focus or remove ability to recieve focus](http://forum.inductiveautomation.com/t/setting-focus-or-remove-ability-to-recieve-focus/2945):
>
> I have a window with many components on it. There is a submit button at the bottom of the screen. After it is press the focus returns to the top left input box on screen. I would really like it to set focus to no component on screen, then user can click into which component they want to change.

According to this, you can't have nothing focused, so try the script in the above post for focusing to the root container  
**EDIT**  
Also, consider using different keys. the function keys, which I tested, worked no matter which component had focus  
Finally, you can use control+left and control+right with a button in focus and it works

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [September 6, 2019, 1:47pm UTC](https://forum.inductiveautomation.com/t/removing-focus-in-a-window/28059/5 "2019-09-06T13:47:44Z")

</div>

From my testing, using the code snippet in my original post in the internalFrameActivated event script, when the window first loads there is no focused component. That code segment actually throws an error stating that “NoneType” has no getName() method.

My hope is that if, when the window initially loads, there is nothing focused, that there would be a way to remove focus from everything via a script method. My hopes may be misplaced, but, as they say, it springs eternal! 😄

---

<div class="post-metadata">

**Author:** ![Alexander41](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@Alexander41](https://forum.inductiveautomation.com/u/Alexander41)\
**Post date:** [November 1, 2019, 8:30pm UTC](https://forum.inductiveautomation.com/t/removing-focus-in-a-window/28059/6 "2019-11-01T20:30:04Z")

</div>

You can try the following to set focus back to the root container.

```auto
root = event.source.parent
root.setFocusable(True)
root.requestFocusInWindow()
root.setFocusable(False)

```
