4

I am writing an app in Python that must be able to send keys or text to another app. For example, if I have Firefox open, I should be able to send it an URL to open it.

I already have the SendKeys module, and I have read about the win32 module too, but I do not know if there is a way to filter out process without open windows.

jesterjunk
  • 2,342
  • 22
  • 18
Eligio Becerra
  • 732
  • 1
  • 7
  • 14
  • Try this: http://stackoverflow.com/questions/14653168/get-hwnd-of-each-window-python Dragonfly is not ported to Python3.x – hemn Jun 16 '13 at 15:04

3 Answers3

5

Usually, for this sort of "GUI automation" pyWinAuto is a good way to go. We use it to allow automated testing of GUI applications, and it ought to let you "type" URLs into Firefox (not to mention finding its window) as well.

jesterjunk
  • 2,342
  • 22
  • 18
Peter Hansen
  • 21,046
  • 5
  • 50
  • 72
3

Even if you need to use automation for everything else your app is going to do, it would probably be a lot easier to use the webbrowser module for opening urls in the user's browser.

jesterjunk
  • 2,342
  • 22
  • 18
Isaiah
  • 4,201
  • 4
  • 27
  • 40
  • Didn't know about this module, but I can grant this is a big headache saver since this is a rewrite from a C# app. And sending command to browser was hell on earth. – Eligio Becerra Jan 07 '10 at 18:55
3

try using dragonfly. It has a whole lot of automation stuff built into it. You don't need the speech recognition part in order to use the automation stuff. For example:

from dragonfly import Window
Window.get_all_windows()

will return a list of all the windows.

you also want to look at the FocusWindow() and Keys() objects in dragonfly.

reckoner
  • 2,861
  • 3
  • 33
  • 43
  • 1
    Dragonfly don't have the Window module anymore. – Leonel Sanches da Silva Oct 12 '14 at 21:26
  • **Update**: Original `dragonfly` has been archived. You can find `dragonfly2` on [GitHub](https://github.com/dictation-toolbox/dragonfly) and [PyPI](https://pypi.org/project/dragonfly2/). `Window classes` were improved https://dragonfly2.readthedocs.io/en/latest/window_classes.html. Code in the above answer is still valid. – Jovial Joe Jayarson Mar 12 '22 at 07:00