# Escape key not firing on child window

**URL:** <https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241>\
**Category:** macOS\
**Created:** [August 25, 2020, 3:41pm UTC](https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241 "2020-08-25T15:41:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [August 25, 2020, 3:41pm UTC](https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241/1 "2020-08-25T15:41:38Z")

</div>

I have a problem with a window’s keydown event not intercepting the Escape Key. I use it here to close the window. I thought it was because it was a modal window, so I eliminated that. The code works fine on a PC.

I’m not sure what else could be causing this. I don’t have any other keydown event.  
The focus is on a texture, but the key works on a PC so, I don’t know what is happening.

Suggestions

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [August 25, 2020, 10:04pm UTC](https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241/2 "2020-08-25T22:04:09Z")

</div>

I added to the TextArea a KeyDown event to make sure the Escape key was being honored. The TextArea did read the Escape key but the return didn’t go anywhere. It ended there.

Yes I did restart my Mac and even did Option-R-Command-P just in case

---

<div class="post-metadata">

**Author:** ![Henry\_F\_Gibson](https://forum.xojo.com/user_avatar/forum.xojo.com/henry_f_gibson/32/686_2.png) [@Henry\_F\_Gibson](https://forum.xojo.com/u/Henry_F_Gibson)\
**Post date:** [August 25, 2020, 10:29pm UTC](https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241/3 "2020-08-25T22:29:29Z")

</div>

Sure you have Return true in the keydown event?

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [August 25, 2020, 10:52pm UTC](https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241/4 "2020-08-25T22:52:18Z")

</div>

Yes. And in just in case the world is crazy, I tried Return False. It didn’t get to the window’s KeyDown.

Edit. Oops. misread my code for my previous edit

---

<div class="post-metadata">

**Author:** ![Sam\_Rowlands](https://forum.xojo.com/user_avatar/forum.xojo.com/sam_rowlands/32/265_2.png) [@Sam\_Rowlands](https://forum.xojo.com/u/Sam_Rowlands)\
**Post date:** [August 26, 2020, 1:17am UTC](https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241/5 "2020-08-26T01:17:17Z")

</div>

How are you detecting the escape key?

I seem to recall that escape on the Mac is ASCII 27

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [August 26, 2020, 1:33am UTC](https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241/6 "2020-08-26T01:33:35Z")

</div>

This is the first line in that window’s keyDown event.  
`If (Key = String.ChrByte(13) Or Key = String.ChrByte(03) Or key = String.ChrByte(27)) And Changed = False Then//Chrb(27) = escape`

This line’s purpose is to close the window

I removed the other Keydown event, since I knew it wasn’t getting here.

At one point I had this as an explicit window. I also had it as Modal, but decided against it in order to have a menu. Menues if I remember right don’t go with Modal windows.

---

<div class="post-metadata">

**Author:** ![Sam\_Rowlands](https://forum.xojo.com/user_avatar/forum.xojo.com/sam_rowlands/32/265_2.png) [@Sam\_Rowlands](https://forum.xojo.com/u/Sam_Rowlands)\
**Post date:** [August 26, 2020, 1:46am UTC](https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241/7 "2020-08-26T01:46:43Z")

</div>

This works for me, providing a text field doesn’t have the focus.

```
select case ASC( key )
case kASCEscape // --- This is a constant defined in OAK2020
  self.close
  
end select

```

Edit: Alternatively, drag a cancel button out on to the window, and position it out of frame. This works, even if the text field has focus.

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [August 26, 2020, 2:17am UTC](https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241/8 "2020-08-26T02:17:56Z")

</div>

Grumble. I’m sure the text area has the focus. I tried the cancel button with its own Keydown and it didn’t work. I think I’ll put the event in the text area and just close it from there.

Thanks also for the idea of a button off of screen. I had always disabled them, but now I might make them work.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 4:37pm UTC](https://forum.xojo.com/t/escape-key-not-firing-on-child-window/56241/9 "2021-04-29T16:37:51Z")

</div>


