Board index » cppbuilder » keyboard event for special characters

keyboard event for special characters


2006-10-19 01:33:42 AM
cppbuilder41
Maybe I am doing this all wrong!
Code follows the narration...
I am retrieving characters from a listbox and sending them one at a
time to a running DOS program. (win2k CMD actually)
The program was selected in a previous routine and the characters are
indeed sent to the open CMD prompt.
I have noticed all character must be in upper case for the cmd to
receive them so, as an example the text box has the following lines in
it.
TELNET MAIL.SOMEWHERE.COM 25
HELO ME
This works but the "." is not interpreted correctly
I discovered that a lower case "n" is interpreted as a .
MAIL FROM: SOMEONE@SOMEWHEREnNET // notice the "n" for a period
RCPT TO: dekaya@SOMEWHEREnNET
But that is not the correct approach because I can't send the needed @
symbol
DATA
From: RemoteAccess
To: XXXX@XXXXX.COM
Subj: What is My IP Address
Bottom line: How do I send CR/LF and special characters
---------------------------------------------------------
void __fastcall TForm1::SendKey(String SCharacter)
{
HWND handle;
handle = FindWindow(NULL, EditTargetApp->Text.c_str());
if(handle != NULL)
{
char *character = SCharacter.c_str();
// bring it to the front
SetForegroundWindow(handle);
// send the letter to the program; parameter MUST be uppercase
keybd_event(*character, 0, 0, 0);
keybd_event(*character, 0, KEYEVENTF_KEYUP, 0);
}
}
 
 

Re:keyboard event for special characters

XXXX@XXXXX.COM wrote:
Quote
Maybe I am doing this all wrong!
Could be.
Quote
char *character = SCharacter.c_str();
keybd_event(*character, 0, 0, 0);
It looks like keybd_event wants a vitual key code as the first
parameter, not an ASCII character.
Take a look at VkKeyScan()
keybd_event( VkKeyScan(*character), 0, 0, 0 );
or
PostMessage( handle, WM_KEYDOWN , VkKeyScan(*character), 0 );
PostMessage( handle, WM_KEYUP , VkKeyScan(*character), 0xC0000000 );
Quote
Bottom line: How do I send CR/LF and special characters
Search your Help for "Virtual-Key Codes" for a list.
VK_RETURN
\n is undefined
You already discovered that period is
VK_DECIMAL 6E Decimal key
otherwise known as ASCII 'n'