When we develop software in Smalltalk, we normally limit ourselves to our Smalltalk image and rarely interact with other applications on the platform. When we do, we use COM, OLE, DDE or sockets to talk to the other application assuming it has a public API we can use. It does, however, get hard to drive Excel, for example, from an OLE interface.
I've recently been doing some work on interfacing to Windows applications by simulating the user events. This has the advantage that it's easy to explain to someone and it doesn't need the application to expose any interface to us or require us to understand that interface.
I've been using pywinauto and sendkeys as inspiration for this work. So far, I have basic control over Windows applications. For example, I can drive Notepad like this:
(WinRemote.Window new)
typeString: '^{ESC}';
delayMilliseconds: 300;
typeString: 'r';
delayMilliseconds: 300;
typeString: 'notepad.exe{ENTER}';
delayMilliseconds: 300
This means, press CTRL-ESC r (for Run...), type notepad.exe and press the ENTER key.
This opens the Notepad application. I can now find that window and start driving it:
(WinRemote.Window withTitle: '.*Notepad')
selectMenu: 'Help / About';
delay: 1;
typeString: '{ENTER}';
typeString: 'This is a test{ENTER}{TAB}of the text entry{ENTER 3}capability+1{HOME}-->';
delay: 1;
selectMenu: 'File / Save As';
delayMilliseconds: 300;
typeString: 'junk.txt{ENTER}'
The strings for the typeString: method can contain special characters such as:
- + SHIFT the next character
- ^ CONTROL the next character
- % ALT the next character
- ~ same as ENTER
- {<keyname>} press the named key
- {<keyname> 5} press the named key 5 times
So far, I've been able to get pretty good control over other windows. If anyone is interested in trying it out, check out the package Windows Remote Control in the public Store repository. This is still a work in progress and I expect to make a lot of changes and improvements over the next few weeks.