0

I want to open a browser, click on some fields and then send keystrokes.

The following code clicks at any point on screen.

win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

Now i want to send keystrokes to that active application. How can i do that?

1
  • "I want to open a browser, click on some fields and then send keystrokes." Wouldn't scrapy do the job? Commented Oct 14, 2013 at 7:33

1 Answer 1

5

I think that library from Google code will do the job: http://code.google.com/p/sendkeys-ctypes/

Check that link also for a sample code:

http://win32com.goermezer.de/content/view/136/254/

import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("outlook")
shell.AppActivate("Outlook")
shell.SendKeys("^o", 0) # 1 für Pause = true 0 für nein
shell.SendKeys("^a", 0)
shell.SendKeys("^c", 0)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but here shell.Run("outlook") how to run any executable..where is "outlook" defined?
In that example, "Outlook" is an executable on the Environment variables (the PATH variable), but you can run any executable, batch file, etc... by specifying the full path as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.