c#textBox1.Text转换为KeyCode并将其发送到SendMessage的聊天程序

时间:2014-11-10 01:52:05

标签: c# string keycode

我有一个Textbox1,我希望将其文本发送到由Virtual Keys工作的程序。

我有这些:

const uint MAPVK_VK_TO_CHAR = 0x02;
public const int WM_SETTEXT = 0x100;

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, stringBulder lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int MapVirtualKey(int uCode, uint uMapType); 

int txL = textBox1.TextLength;
for (int o = 0; o < (txL-0); o++)
{
     int key = MapVirtualKey((int)textBox1.Text[o], MAPVK_VK_TO_CHAR);
     SendMessage(hwndTarget, WM_SETTEXT, key, new StringBuilder(key.ToString());
}

我只想知道是否存在任何可以将TextBox的任何char转换为KeyCode的函数? 我可以写一个switch : case,但这太长了。 (它也包含所有的unicodes语言:S)

0 个答案:

没有答案