I am using System.IO.Ports.SerialPort.ReadChar to read characters from the serial port. I need to be able to send the characters as virtual keypresses using the keybd_event function, and I just can't seem to figure it out.
This is about what I am trying to do:

void COM1_DataReceived(object sender, SerialDataReceivedEventArgs e) { int c = COM1.ReadChar(); byte key = (byte) MapVirtualKey((uint)keyCode, MAP_SCANCODE_TO_VK); keybd_event(key, (byte)c, KEYEVENTF_KEYDOWN, 0); keybd_event(key, (byte)c, KEYEVENTF_KEYUP, 0); }This only works when I type capital letters (which come through as the correct letter but in lower case.) Am I using keybd_event wrong, or MapVirtualKey? Is there any way to achieve this short of defining my own array of key codes for every visible character?
I think most of my problems are coming from a misunderstanding of the meaning of virtual keys, scancodes, and the return value of SerialPort.ReadChar. Can anyone help me clear this up?


More...