I dug in to some very old c code of mine for the solution. I didn't expect it to work but I'm not complaining. Here is the SIMPLE solution for anyone that is interested: Add to your project: using System.Runtime.InteropServices; [DllImport("coredll.dll")] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); Then add this function, please note many of the original C constants are not valid in C# but you can look them up and define them for WM 5.0 if you need them. My app only needed to worry about alphanumeric data, no special characters. static void SendKeyStroke(int mevent) { //******************************************************* //send character to screen by simulating a key press //******************************************************* int evt = 0; byte keyCode = 0x00; //SPECIAL KEYS ************* const int KEYEVENTF_EXTENDEDKEY = 0x1; const int KEYEVENTF_KEYUP = 0x2; const int VK_RETURN = 0x0D; const int VK_SHIFT = 0x10; const int VK_SPACE = 0x20; //************************** evt = mevent; /* //these codes are not defined switch(mevent) { case 258: evt = VK_DOWN; break; //down arrow case 259: evt = VK_LEFT; break; //left arrow case 300: evt = VK_RETURN; break; //return key case 301: evt = VK_UP; break; //up arrow case 302: evt = VK_BACK; break; //back space key case 10: evt = NULL; break; //do nothing case 59: evt = VK_SEMICOLON; break; // ; case 61: evt = VK_EQUAL; break; // = case 44: evt = VK_COMMA; break; // , case 45: evt = VK_HYPHEN; break; // - case 46: evt = VK_PERIOD; break; // . case 47: evt = VK_SLASH; break; // / case 91: evt = VK_LBRACKET; break; // [ case 92: evt = VK_BACKSLASH; break; // "\" char case 93: evt = VK_RBRACKET; break; // ] case 39: evt = VK_APOSTROPHE; break; // ' //shifted keys(same order as above) case 58: evt = VK_SEMICOLON; keybd_event(VK_SHIFT, 0, 0, 0); break; //colon : case 43: evt = VK_EQUAL; keybd_event(VK_SHIFT, 0, 0, 0); break;//plus +
jpeternel
Posts
-
pinvoke to send text in a console app -
pinvoke to send text in a console appI thought I would also mention that this sample code below for win32 c# does nothing. It runs but no message is displayed in the console. I'm using VS 2005. I find this example all over the net. using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program { [DllImport("msvcrt.dll")] public static extern int puts( [MarshalAs(UnmanagedType.LPStr)] string m); [DllImport("msvcrt.dll")] internal static extern int _flushall(); public static void Main() { puts("Hello World!"); _flushall(); return; } } }
-
pinvoke to send text in a console appHi I'm trying to write a WM 5.0 console application which can send string data to a text box on a web page (Internet Explorer). Any suggestions on this?
-
pinvoke to send text in a console appI should mention this is a C# console application