-
Notifications
You must be signed in to change notification settings - Fork 130
ControlPrograms
On Windows, MH can control any program that is running on your computer by providing commands as if you were pressing keys on the keyboard. Most Windows show valid key commands with an underlined or bold letter in the dropdown menus. Sometimes these are activated with shift, control or alt keys. Often if you keep hitting TAB a form of highlight will move around the screen from field to field. Sometimes these functions are documented but otherwise you can systematicly try every key, including with shift, alt, and control to see what they do. There are often hidden features.
SendKeys creates the equivalent of keyboard presses for a running program. So you can effectively type 'hello world' remotely but some things need a bit of a fiddle. To send eg "alt f" you send "alt" then "f" then deactivate " alt" with "alt-". But to send "alt" rather than "a", "l", "t", you send \alt\. But \ is a special character so it has to be escaped with \, so you actually send \\alt\\. phew!
SendKeys is documented in mh/lib/site_win50/win32/setupsup.html so you have probably already come across it.
Actually sendkeys is a subroutine called with some arguments so first you need to find out if your program is running and if so how to refer to it. This is done with another subroutine sendkeys_find_window(window title, program name). This returns a handle to use in SendKeys so it needs to be saved, but if the program isn't there it returns nothing or false (I'm not sure) so it can also be used as a test like this:
code if (my $window = &sendkeys_find_window('WinTV32', 'WinTV32')) {
- now we can send a keystroke to the program which in this example is a WinTV? video capture card
the 300 is a delay between keys to give the program time to do things, adjust for your CPU speed, I'm running 1500MHz. Start with a bigger number to see how it works. I'm not sure what the 0 does.