Sending text from my program to an existing program text window

Here is the situation. At my work, we use an existing program that allows you to scan barcodes into a set of records. The problem is that to create this set of records, we must scan each item separately. We click the "Add" button, which displays the text field, and we scan the barcodes into it (or you can enter it)

To prevent this, I created a C # program that creates a list of barcodes, and I was looking for a way to simply set up a simple copy and paste type setting that would copy the barcode, paste it into the text box of existing programs, and maybe send return char so that it is ready for the next barcode. He would just send each barcode one at a time until he went through the list.

I have control over my C # program, but the working program is not built by me, and I do not have access to the code or any apis used. Can anyone suggest a solution that might work for this? I found something like SendMessage, but I'm not quite sure how it works, as it says I need to do a search first.

+3
source share
3 answers

, http://inputsimulator.codeplex.com/. , :

  • -
  • ,
  • -
  • return

API, , . , !

+2

SendMessage, spy ++ , . , API- settext, . WM_KEYDOWN, WM_KEYDOWN .

http://msdn.microsoft.com/en-us/library/ff468861%28v=vs.85%29.aspx

[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

private const int WM_KEYDOWN = 0x0100;
private const int WM_KEYUP = 0x0101;

:

SendMessage(textboxHandle, WM_KEYDOWN, KeyCode, null);
SendMessage(textboxHandle, WM_KEYUP, KeyCode, null);

; http://msdn.microsoft.com/en-us/library/dd375731%28v=vs.85%29.aspx

+1

You can use the UI Automation framework , which is part of .NET 3+.

Then you used the UISpy tool to extract the necessary information about the text field, about which you can go into your C # application and the automation infrastructure of the user interface.

An example exists through an MSDN Magazine article .

0
source

Source: https://habr.com/ru/post/1788022/


All Articles