Question

This may be a cardinal programming sin, but what's the easiest and quickest way via executable or batch file to bring focus to Window X and hit keystroke Y? This won't be reused, and X and Y can be hard-coded if necessary.

edit: on a Windows machine

Was it helpful?

Solution

You can try AutoHotkey or use win32 API as MusiGenesis suggested.

OTHER TIPS

Use the Win32 API calls FindWindowEx and SendMessage (or SendNotifyMessage if you want control to return to your application immediately without waiting for the receiving application to process the message).

Assuming this is Windows, of course.

This isn't really much of a sin, by the way. There are much more evil things that a program can do than sending keystrokes to other applications (e.g. randomly deleting files, emailing porn to your grandmother etc.).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top