We help IT Professionals succeed at work.

Enter key emulation trough Windows messages

saulite asked
I need to know, how i can send 'ENTER' key signal using windows messages (WM_KEYDOWN/WM_KEYUP or WM_CHAR).

Wich message(s) should i use?
What must be in wParam and what in lParam?

That's all. A very simple queston.
Watch Question

It's not entirely clear what you're looking for.  Do you want to send this to an edit control, a dialog box, a button?  It kind of depends on what you're trying to do.  For example, to generate an enter in a multi-line edit control, I'm sure you could get away with sending a WM_CHAR.  But to close a dialog with the default button, WM_COMMAND might be a better choice.

However, check out the keybd_event() function - or the SendInput() function if you're only coding for Win2000/NT.  Are you looking for something like that by any chance?

Good luck!


i need to send message to ANOTHER program. If i'd need to send to my program, i'd used keybd_event.

can i send VK_RETURN using WM_CHAR? if yes, then how, if not - how i can do this  using WM_KEYDOWN combining with WM_KEYUP.
Try one of the following:

PostMessage (hwnd, WM_CHAR, VK_RETURN, 0x011C0001);


SendMessage (hwnd, WM_KEYDOWN, VK_RETURN, 0x011C0001);
SendMessage (hwnd, WM_KEYUP,   VK_RETURN, 0xC11C0001);

Explore More ContentExplore courses, solutions, and other research materials related to this topic.