Skip to content
Lieven Hollevoet edited this page Sep 22, 2014 · 1 revision

We don't want the Twiki to be no more than a code depository, but for the moment this snippet is the best way to illustrate this tricky example of using sendkeys.

code

  1. Category= Security

=begin comment This program illustrates the use of sendkeys to control a program (WinTV32) and capture TV pictures from a Hauppage WinTV? card. Sendkeys creates the equivalent of keyboard presses for a running program. Most Windows show valid key commands with an underlined or bold letter in the dropdown menus. Otherwise you can systematicly try every key, including shift, alt, and control versions to see what they do. There are often hidden features. 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! The basis is an original program by Jeff P. which captures pictures and files them under date and time. The unused bits of that are commented out. My cheat to speed it up just gets the picture into a holding file in \ia5\security\images by first manually saving a picture there in WinTV32 so that the program remembers that location. Then I changed the img tag in ia5\security\main.shtml to img src="images/Q.jpg" so the security web page displays it. Baz =cut # ------------------------------------------------------- $v_CaptureWinTv32 = new Voice_Cmd("Capture Camera");

if (said $v_CaptureWinTv32) { &CaptureWinTv32 ; }

  1. -------------------------------------------------------
sub CaptureWinTv32? { speak "start capture";
  1. my $string1 = '\\ALT\\f\\ALT-\\a\\ALT\\t\\ALT-\\j\\ALT\\n\\ALT-\\';
  2. my $FileName = sprintf("Car_%s_%2.2i__%2.2i_%2.2i_%2.2i",$Year_Month_Now, substr($Date_Now, 9, 2), $Hour, $Minute, $Second);
  3. my $FileName = "frontdoorcam";
  4. my $string2 = '\\TAB\\\\TAB\\\\TAB\\\\TAB\\\\TAB\\\\TAB\\\\TAB\\90';
my $string1 = '\\ALT\\f\\ALT-\\a'; my $string3 = '\\ALT\\s\\ALT-\\'; my $FileName = "Q"; # long names are slow

my $KeyCommand = $string1.$FileName.$string3;

  1. my $KeyCommand = $string1.$FileName.$string2.$string3; # building command like this is versatile
  2. WinTV32 must be running, but you can minimise it
if (my $window = &sendkeys_find_window('WinTV32', 'WinTV32')) { &SendKeys($window, $KeyCommand, 0, 300); # the 300 is a delay between key to give the program time,
  1. adjust for your CPU speed, I'm running 1500MHz. Start with a bigger number to see how it works
print_log "Picture captured"; }
  1. my $SourcePath = 'c:\mh\mh\web\images\\'.$FileName.".jpg";
  2. my $DestPath = 'E:\mh\data\proxy\carftp\\'.$FileName.".jpg";
  3. print_log "CarCam SourcePath?: $SourcePath";
  4. print_log "CarCam DestPath?: $DestPath";
  5. my $rc = copy("$SourcePath", "$DestPath") or print_log "Error copying carcam to proxy: $!";
  6. print_log "CarCam copy results: $rc";
} #end of sub, don't forget this

code

-- BazUK - 13 Mar 2004

Clone this wiki locally