I have this problem and don't know where to start. I need to write a program that will run in WinCE, so Compact Framework will be required, and this program has to write text (a string) wherever the cursor is. I mean, if my program is running, and the cursor is in a notepad window. the text must be displayed in notepad. Or if the cursor is in another application inside a textbox (or textfield if that app was wrote in java), the text must be placed in that textbox.
I'm able to d开发者_开发知识库o all the other functionality the program requires, but I don't know how to do this. As far as I have read, it is done with API's. And that is all I can understand.
Any help will be apreciated.
Thanks!
The first thing that comes to mind is SendKeys. It's a simple way to emulate typing.
We use P/Invoke keybd_event to generate keyboard entry. The only other approach I can think of would be to put your string in the clipboard, and generate a paste key stroke. I'm not sure every app you encounter is going to respond to CTRL+V the same. Perhaps there's a way to trigger the paste programmatically from your app?
[DllImport("coredll.dll", EntryPoint = "keybd_event", SetLastError = true)]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
This should generate a silent A keystroke.
keybd_event((byte)Keys.A, 0, 0, 0x0004);
keybd_event((byte)Keys.A, 0, 0x0002, 0x0004);
精彩评论