Skip to main content
Participant
February 20, 2011
Answered

How to detect when the enter key is pressed

  • February 20, 2011
  • 1 reply
  • 1096 views

I'm using a texteditbox on a panel to take input from the user. I want to process the contents of the input box when the enter key is pressed in the edit box. I'm wondering as to how I would be able to detect the enter key being pressed? Any pointers would be appreciated. Thanks in advance.

This topic has been closed for replies.
Correct answer Markus Freitag

Hi,

yes, if you want to do anything only if the enter key is being pressed you must implement an IEventHandler and check the virtual keys kReturnKey and kEnterKey.

Markus

1 reply

Inspiring
February 21, 2011

Hi,

add an observer to your TextEditBox and observe it for PMIID IID_ITEXTCONTROLDATA and the change ClassID message kTextChangeStateMessage.

Markus

Participant
February 21, 2011

Hi,

Thanks Markus for the help , but I tried this method and found a problem in this implimentation: the event fires even on tabpress, or clicking on any other widget, etc. ( i think whenever the texteditbox widget looses input focus.) I want to process the text box content only when the 'Enter' key is being pressed, and not on other situations when the widget looses focus. I hope i'm being clear enough.

I'm thinking I may have to somehow use the KeyDown() event, maybe by writing an own implimentation for IID_IEVENTHANDLER, but am not quite sure (I'm just a beginner).

Markus FreitagCorrect answer
Inspiring
February 22, 2011

Hi,

yes, if you want to do anything only if the enter key is being pressed you must implement an IEventHandler and check the virtual keys kReturnKey and kEnterKey.

Markus