I have explored sendkeys and wm messages however I am perplexed. Sendkeys only sends keys to an active window, not a specific region. I have an application I want to send key presses to, but only in particular locations. For example, the app has 4 sections, I want to copy all the text (using ctrl+a) from section 2 at 2350,185. But if I send the keys ctrl+a to the app, it trys to copy all sections, or the last section it was in. How can i send ctrl+a to the coordinates 2350,185?
Asked
Active
Viewed 531 times
-1
-
That makes no sense, a keyboard message doesn't have a position associated with it. Only mouse messages have that. You'll send to the window that's in the foreground and has the focus. That being the wrong window is a very common issue. – Hans Passant Jul 10 '14 at 17:32
-
If i click the window (the whole app) and press ctrl a it does what send keys does. If i click in section 2 and press control a, it copies section 2. How do i set the cursor position (i guess) in the app then press ctrl a? – user3753620 Jul 10 '14 at 17:33
-
what in the world is section 2? – Ňɏssa Pøngjǣrdenlarp Jul 10 '14 at 18:09
-
Call .Focus on the control you want the cursor to be in before sending the keystrokes. – Bradley Uffner Jul 10 '14 at 18:32
1 Answers
0
It sounds like you need to have focus set to a specific control before sending keys to the application. You can set the input focus to a particular control by calling .Focus
on the control before calling SendKeys
If the control is in a different application you will have to resort to API calls using P/Invoke and basically send the windows message to the correct control to set the focus. This is not a simple task.

Bradley Uffner
- 16,641
- 3
- 39
- 76
-
Check this link for an example of setting focus in a different application. http://stackoverflow.com/questions/9503027/pinvoke-setfocus-to-a-particular-control – Bradley Uffner Jul 10 '14 at 18:36