1

I have a Textbox1 and I want send its text to a program that is working by Virtual Keys.

I have these :

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());
}

I just want to know if any function exists that can convert any char of TextBox to KeyCode ? I could write a switch : case but this will be too long. (it contain all unicodes languages too :S)

  • possible duplicate of [How to convert a character to key code?](http://stackoverflow.com/questions/2898806/how-to-convert-a-character-to-key-code) – Blorgbeard Nov 10 '14 at 02:27
  • Also related: http://stackoverflow.com/questions/3152299/convert-character-to-virtual-key-code – Blorgbeard Nov 10 '14 at 02:27
  • I saw them but my problem is in textBox1 , it will be fill by my program and i want to convert it to keycodes , btw i want to use sendmessage too. – Hessy SharpSabre Nov 10 '14 at 02:54
  • 1
    `textBox1.Text` is just a string. You're already breaking it into characters. The related questions deal with characters. What's the problem? – Blorgbeard Nov 10 '14 at 02:58
  • i think ,this function is for VK to char , i want be reverse of it. – Hessy SharpSabre Nov 10 '14 at 03:00
  • No, it's char to VK. Read this answer: http://stackoverflow.com/a/2899364/369 – Blorgbeard Nov 10 '14 at 03:03
  • So , can you edit it into my problem ? idk how to use that ! – Hessy SharpSabre Nov 10 '14 at 03:19
  • I'm not going to spoon feed you. If you can't read that question and answer and apply it to your own problem youself, you are going to have a lot of trouble implementing the rest of your program. Did you write the code you posted? Do you understand it? You appear to be acting like a [help vampire](http://meta.stackoverflow.com/questions/258206/what-is-a-help-vampire) to me. – Blorgbeard Nov 10 '14 at 03:26
  • ok , i tried to use that solving post and it was success for me , but there is a little problem : that function can't retval the "!" and it can't support all unicode characters . – Hessy SharpSabre Nov 10 '14 at 03:48
  • and this is my problem at there : `if((modifiers & x) !=0) retval |= Keys.Attn;` what must be "x" ? – Hessy SharpSabre Nov 10 '14 at 05:09

0 Answers0