Enter Key In Text Field = Beep (Windows)

I notice that pressing the enter key in a text field results in the standard Windows Alert warning to be played. This is the same sound when a MsgBox opens. I have a login screen with the default button specified. After the user enters their password and presses enter there is a alert message that is played. I thought it was related to the default button but it can be duplicated by just adding a text field to a window and running it.

It’s annoying - Is there a way to disable this? I would imagine I can trap the key and return true from the event if the enter key is pressed but this seems kluudgy. I haven’t verified that yet…

Thanks.

Add something like this in the Keydown event handler of the TF :

Return  (Key = chr(13))

BTW it is not kludgy. It is the way you filter keys in Xojo.

[quote=387131:@Joseph Evert]I notice that pressing the enter key in a text field results in the standard Windows Alert warning to be played. This is the same sound when a MsgBox opens. I have a login screen with the default button specified. After the user enters their password and presses enter there is a alert message that is played. I thought it was related to the default button but it can be duplicated by just adding a text field to a window and running it.

It’s annoying - Is there a way to disable this? I would imagine I can trap the key and return true from the event if the enter key is pressed but this seems kluudgy. I haven’t verified that yet…

Thanks.[/quote]
The default button should be capturing the enter key. I have no issues with this here, and there are no kludgy keydown traps in my test.

Tim,

If you drop a textfield on a window and run the application and hit the enter key while in the text field is does not beep? I am on Windows 10.

The default button works, but I am trying to eliminate the beep that is generated when the enter key is pressed in the text field.

[quote=387137:@Joseph Evert]Tim,

If you drop a textfield on a window and run the application and hit the enter key while in the text field is does not beep? I am on Windows 10.

The default button works, but I am trying to eliminate the beep that is generated when the enter key is pressed in the text field.[/quote]
If there is a default button it should be capturing the enter key and Windows should not beep. If there is no enter button, it should beep as there’s no action to perform and the user hit the enter key expecting an action.

Circumventing these usage paradigms would be a terrible choice.

I agree completely, but that is not the behavior I am seeing. My issue is whether I have a default button or not, when pressing the enter key in a text field it makes the beep.

In my case the end result is that the user enters their username, password and after keying in their password they hit enter, which of course activates the default “login” button. The problem is that it beeps and the user says “why, what just happened?”

It’s easy to duplicate. A simple window with a text field, default button and label. In the default button action event put label1.text = “button fired” so you know the button was fired. Enter something into the text field and hit enter - it beeps. Why?

If you enter the text then press the button with the mouse, no beep. This seems definitely related to the text field.

It seems the answer has already been given…return True if the enter key is pressed whether or not you have a default button

Not really… This prevents the default button from firing; returning the enter key or True. The only workaround I see is to catch the enter key in the text field key down event then utilize button.push() in the key down event to trigger the button. Similar to Michel’s suggestion above.

This seems like a bug to me, which is very easy to duplicate.

It’s not a bug Joseph, it’s standard behavior.

A text field is not the same as text area. Text Area will allow you to input a Carriage Return + Line Feed as it should. A text field is only one line, so pressing the Return key (beep) alerts the user to the fact that they cannot enter multiple lines of text. It’s normal.

Perhaps what you are referring to is the Enter Key as in COMMIT this action. This is normally the Enter Key at the bottom r/h of the keyboard near the numeric keys. I think it’s the same ascii character (13)?

Capture the event as Michel suggested and use button.push if you like, or just run the same method that’s in the button action event.

It’s a feature, not a bug. :slight_smile:

Put whatever code you want to run with the Default Bin -OR- the Enter Key in a separate method. Then call that method returning True from the TextField or just calling it from the action event of the Default Btn.
This is what I do on all of my apps and what, I believe, most Xojo programmers do in this situation.

Great, thanks for all the input!!