# Textfield KeyDown

**URL:** <https://forum.xojo.com/t/textfield-keydown/29952>\
**Category:** General\
**Created:** [February 24, 2016, 5:05pm UTC](https://forum.xojo.com/t/textfield-keydown/29952 "2016-02-24T17:05:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_T](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@Martin\_T](https://forum.xojo.com/u/Martin_T)\
**Post date:** [February 24, 2016, 5:05pm UTC](https://forum.xojo.com/t/textfield-keydown/29952/1 "2016-02-24T17:05:05Z")

</div>

Hi,

I have a Textfield and i want it to accept only Digits 0-9, Backslash, Delete, Tab, Right and Left Key. How to handle this?  
[h]Sample[/h]

`Select Case Key
Case Chr(8)
  Return False
Else
  Return True
End Select`  
Won’t work!

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [February 24, 2016, 5:21pm UTC](https://forum.xojo.com/t/textfield-keydown/29952/2 "2016-02-24T17:21:31Z")

</div>

[code]Event KeyDown(key As String) As Boolean  
Const LOWEST\_DIGIT = 48  
Const HIGHEST\_DIGIT = 48  
Const BACK\_SLASH = 92  
Const DELETE = 127  
Const TAB = 9  
Const LEFT = 28  
Const RIGHT = 29

Select Case Asc(key)  
Case LOWEST\_DIGIT To HIGHEST\_DIGIT, BACK\_SLASH, DELETE, TAB, LEFT, RIGHT  
Return False  
Else  
Beep()  
Return True  
End  
End[/code]  
The keycode constants depend on the OS and the language settings of its user.

---

<div class="post-metadata">

**Author:** ![Martin\_T](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@Martin\_T](https://forum.xojo.com/u/Martin_T)\
**Post date:** [February 24, 2016, 5:31pm UTC](https://forum.xojo.com/t/textfield-keydown/29952/3 "2016-02-24T17:31:22Z")

</div>

Cool Eli Ott. And there is no way to do have Platform Independent Solution?

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [February 24, 2016, 5:36pm UTC](https://forum.xojo.com/t/textfield-keydown/29952/4 "2016-02-24T17:36:04Z")

</div>

All printable characters are cross-platform. I don’t know about arrow keys and the like.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [February 24, 2016, 5:43pm UTC](https://forum.xojo.com/t/textfield-keydown/29952/5 "2016-02-24T17:43:49Z")

</div>

> [@249270:@Eli Ott](#):
>
> All printable characters are cross-platform. I don’t know about arrow keys and the like.

In Xojo, AFAIK arrow keys are cross platform between Mac and Windows. Probably Linux as well.

---

<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:** [October 29, 2020, 6:12pm UTC](https://forum.xojo.com/t/textfield-keydown/29952/6 "2020-10-29T18:12:17Z")

</div>


