pinvoke to send text in a console app
-
Hi 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?
-
Hi 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?
I 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; } } }
-
Hi 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?
For mentioning and re-mentioning, you can always use Edit link at bottom right of your post.
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
-
Hi 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?
The only way to send text to a web page, is to host that web page in your own windows application, so you can directly access and change the HTML of the page.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
The only way to send text to a web page, is to host that web page in your own windows application, so you can directly access and change the HTML of the page.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
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 +