I am writing a program for Windows, which should send the Enter key to the dialog box to close it automatically.
I extract the handle to the top-level window that interests me (using EnumDesktopWindows ()), and then try sending the ENTER key using SendMessage (note also that closing the window by sending WM_CLOSE works fine).
None of the following works:
SendMessage( hTargetWindow, WM_CHAR, VK_RETURN, 0 );
SendMessage( hTargetWindow, WM_CHAR, VK_RETURN, 1 );
SendMessage( hTargetWindow, WM_KEYDOWN, VK_RETURN, 1 );
SendMessage( hTargetWindow, WM_KEYUP, VK_RETURN, 1 );
SendMessage( hTargetWindow, WM_KEYDOWN, VK_RETURN, 1 );
SendMessage( hTargetWindow, WM_CHAR, VK_RETURN, 1 );
SendMessage( hTargetWindow, WM_KEYUP, VK_RETURN, 1 );
etc.
As a possibly simpler scenario, I also tried sending the ascii key, say, to notepad.
How should this work?
Thanks in advance
source
share