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?

kofhearts
  • 3,607
  • 8
  • 46
  • 79

1 Answers1

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)
Rami
  • 7,162
  • 1
  • 22
  • 19
  • Thanks but here shell.Run("outlook") how to run any executable..where is "outlook" defined? – kofhearts Oct 14 '13 at 21:04
  • 2
    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. – Rami Oct 14 '13 at 23:04