views:

382

answers:

4

I am developing a small app for a Motorola 9090-G using .net compact framework 2.0.

My problem is that I can't seem to detect an enter keypress in a textbox. How do you detect an enter keypress in a textbox?

None of the 3 detection methods seems to work. Interestingly, it DOES work in the ppc emulator. It does not work on my actual hardware however.

private void tbxQTY_KeyDown(object sender, KeyEventArgs e)
    {    
      if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter || e.KeyCode == Keys.Decimal)
      {
        QTYEntered();
        e.Handled = true;
      }

      if (e.KeyData == Keys.Enter || e.KeyData == Keys.Return)
      { do something }


      if (e.KeyValue == (char)13)
      { QTYEntered(); MessageBox.Show("test"); e.Handled = true; }
    }
+1  A: 

For me the answer was to use the KeyPress event, not KeyDown:

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == 13)
        {
            // Enter
        }
    }
Cheeso
A: 

The device may not be handling the button press in a way that is accessible to you.

Have you checked that the event is actually being triggered?

If not, you may want to look at other events or possibly capturing HardwareButton presses instead.

Matt Lacey
A: 

OEMs configure their keys differently sometimes. The trick is to create an app that just handles the key up and key down events and then query the values you get when pressing the relevant keys. YOU MAY BE SUPRISED at the results.

I had an Intermec unit once. Enter was correctly enter, however the ACTION key was Enter followed by F23 about 10 ms later. God... that was hard to code around to make that key useful (i.e. do something that wasn't the same as the enter key). The solution included a function called:

public bool IsReallyEnter(KeyEventArgs e);

KeyPress is an okay workaround, your issue is that it will fire multiple times if they hold the keydown.

Quibblesome
A: 

This is how I do it now to navigate between fields and on the "last" field, I call my save function. I do not miss a key:

Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        Select Case e.KeyCode
            Case Keys.Enter
                ComboBox2.Focus()
        End Select
    End Sub
0A0D