Open process & paste text within this process - c#

I need to Open a process (easy)
and then somehow paste data from my application into this opened application into it's currently active textbox.
How can I get that done?

using the windows clipboard seems like an easy option, if the user can paste manualy, or you control the code for both applications and can make both work with the clipboard
EDIT
Using win 32 api's send message can provide the answer as well, especially if you dont control the code for the process you want to write into, and want it to be 100% automatic.
Check out these links
https://stackoverflow.com/a/4539229/1394380
How to send text to notepad
win 32 api messaging with send message
The general steps for this solution are: to find the text box, using the FindWindow function and then send the text, using the send message. Note: As far as i understand, the receiving application, should yet have a handler for the message and update accordingly

Related

SendKeys very Slow in Windows Window

I use Selenium with the latest Chromedriver, the Script opens a Windows Window to Select a Picture to Upload.
It's working, but the typing is so slow, like slow-motion 10 Letters > 3-5 Sec....
I use this Command:
SendKeys.SendWait(...);
On the other Side, in the Chrome Window, the SendKeys is so fast, you can't see that is typing, the text is instant here, but not in the Windows Window for Uploading a Pic...
driver.FindElement(By.XPath("...")).SendKeys("...");
Anyone have an Idea why that happens and how I can solve this?
Maybe this will help you
How to handle windows file upload using Selenium WebDriver?
I think
SendKeys.SendWait(...);
is working this way - add a list with letters, then type first, waits when completed and only then adding next one. That why adding more letters will take longer to complete it.
There is Remark from - https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.sendwait?view=windowsdesktop-6.0
Use SendWait to send keystrokes or combinations of keystrokes to the active application and wait for the keystroke messages to be processed. You can use this method to send keystrokes to an application and wait for any processes that are started by the keystrokes to be completed. This can be important if the other application must finish before your application can continue.
Your Selenium code:
driver.FindElement(By.XPath("...")).SendKeys("...");
Is adding your full string of text from your "..." to web element.. that why your full text is already in your element. Same as copy and paste.

get status info Windows Media Player (stand-alone application)

I want to write an application which gets the status information about a running WMP thread, like playing/paused, shuffle mode on/off, repeat on/off, song title or media file path.
I was using the P/Invoke SendMessage-function to "simulate" a click on the play/pause/stop etc. buttons, but I'm unable read the values of labels/text boxes inside the WMP application with WM_GETTEXT.
I used Spy++ to get the handles of certain text fields - but they (obviously) change their handle after restarting the WMP.
Does somebody know a answer to this Problem?
It could be anything - P/Invoke or SendKeys - but not this AxWindowsMediaPlayer, because my application is a console app and I want the status information of the external process - not of my own.
Thanks
I will mark this thread as 'answered'.
I have solved this problem a few months ago, but lost the source code.
The aim of this application is to control the WMP via sshd or telnet.
You can download the binaries here if you want to:
WMP.rar (27 KB)
https://mega.co.nz/#!ug5DySRR!rQlI9OZZ8wYq7yAqaH-KYsmCl9LSaBjNdvqX0g_WDtI
The application is executed via console. You can see the commands by typing >wmp help

When using SendInput how can I tell when the receiving window has received and processed the messages?

I'm using the Input Simulator library to simulate input to another application using C#, this uses the SendInput API calls. Does anyone know if there is a way I can monitor the windows message queue for the external application to see if those messages have been processed?
For example, let's say I want to send the keystrokes for the word "Hello" to notepad, but I don't want my application to continue until notepad has received and processed the input and the word "Hello" has appeared in the notepad window. We'll know this has happened once the keypress messages are no longer in the message queue for notepad, but I can't work out how to find that out.
I was using the .NET SendKeys class and using SendWait, but this seems unstable and causes occasional freezes in the external application, so after weeks of trying to fix that I'm looking for a new method.
Many thanks
You can't. Calling SendInput ultimately results in posted messages which are delivered asynchronously.
Why fake input to Notepad when you can send the text direct to the edit window? Not only would it be way simpler it would be robust and synchronous.

How do I reliably invoke clipboard copy/paste actions in other apps without messing with input queue

A while ago I wrote a simple app, which surrounds selected text in any input field in any application with some unicode symbols when user presses some hotkey. Basically, app's logic is as follows:
Register global hotkey.
Hotkey fired, now set clipboard monitor and invoke clipboard copy to see if some text was selected.
If clipboard has changed and now contains text, surround said text with symbols and then invoke clipboard paste, so input field will be updated with modified text.
The problem is, I can't get copy/paste functionality from other apps in a reliable way. What I have tried to date:
If I send WM_COPY/WM_PASTE, it's more often ignored than not, depending on the application.
If I use SendInput, keybd_event or any other keyboard-messing stuff to press/unpress usual clipboard hotkeys, it will often tamper with user-pressed keys: copy/paste uses control or shift, which are also quite popular for all generic hotkeys in all apps, my app included.
If I use Journal Hook to directly inject keyboard messages into system input queue, sometimes it will work fine, and sometimes weird glitches will occur. Also, other applications may be using JournalHook for themselves, and that will mess my app badly. Not to mention that default security policies make journal hook hard to use.
I've been trying to get/set text in the input fields using Windows UI automation instead of clipboard magic, but it rarely works.
So, if you know other ways to make other applications reliably use copy/paste functionality, or can even devise entirely different approach, I'd really appreciate you telling me :)
I think your approach isn't that bad, maybe you can start with WM_DRAWCLIPBOARD so you can monitor the clipboard. A nice sample code can be found here.
Next I'd take a look at SendKeys class - Attention: Flush, Buffer, etc. Use this to send ctrl+c/v instead of a windows message! You should get a notification from your monitor if it worked.
Now I'd use the Cliboard class to maniplulate the Data and paste it back.
Oh, it seems that I could only find more or less reliable way of invoking copy-paste without SendInput or journal hook, but I have to deal with it :-) So here it is, in case someone find it useful:
Remember and reset keyboard modifiers via AttachThreadInput(yourAppThreadId, targetAppThreadId) + SetKeyboardState(keyStateWithoutKeyboardModifiers).
Set Ctrl key modifier via SetKeyboardState(keyStateWithControl) for Ctrl+C/V hotkey.
Then PostMessage to focused control handle with WM_KEYDOWN message for C or V key, whether you want it to copy or paste.
Call Thread.CurrentThread.Join(20) to let other app process messages — and that's the most retarded moment in the whole deal, since I couldn't find the sure way to know when other app will have empty message queue.
Restore remembered keyboard modifiers.
Also, every time you do SetKeyboardState, call SetForegroundWindow(focusedControlHandle) and SetFocus(focusedControlHandle) afterwards.

Integrate C# Desktop Application With Browsers

I have developed an application(downloader) using C# now i want to integrate it to browser like i want to place a button in browsers if user press that button then my app should execute & start downloading the required file.
I'm largely guessing, but it sounds like you are talking about a "protocol handler", i.e. to handle hyperlinks to "yourapp:some-stuff-here". If so, try looking at Registering an Application to a URL Protocol on MSDN, which gives a C# example of this.
I don't think that what you want is possible, you can however place a link to the executable and tell your users to execute it via the Browser download options (The Dialog that pops up when you click on some download link that asks wether you want to open oder save the file).
It is not possible to immedatly run your GUI application on a browser button click.

Categories