Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is it possible to emulate keyboard strokes

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
US
It is possible to emulate keyboard strokes with perl? Specifically, I want to select an open window and send a series of keystrokes to it. It this possible and if so how? TIA.
 
Since I got no reply, I'm bubbling this back up to the top.
 
Bad etiquette to bump.

I tagged this one myself coz I'm interested

Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
awingnut,

This may sound a little obtuse, but you could use office to do it.

You can use Perl to open an office document, and within the document have an autload function which would use

Application.SendKeys

Or you could use an app like Macro Express though here you would most likely need to know that state of the machine in terms of relevant window positions, and would be a right pain in the *******.

Another place to look would be CPAN for some of the testing modules

I'm assuming you're on a M$ platform - apologies if I'm wrong

Any decent test suite should have the ability you're after, which you could shell - none too elegant

Sorry If I haven't been too much help here, but it might put you on the right track

Ectually search.cpan.org, look for keystrokes, Win32::GuiTest (ernesto Guisado) could be the biscuit you quest or GUITest.xs ( a Pure Perl implementation, brilliant, but I've only ever got one to work ;(

HTH
Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Thanks for the reply and apologies for the bad form, bumping.

I'll look into your suggestions which I presume imply the answer to my subject question is, "no."

I have Personal Rexx somewhere which does have that capability but I was hoping not to have to use so many different products for a seemingly simple task.
 
Look up the Win32::TestGUI, I only thought of that as I was closing the comment, and didn't have much of chance to look it up fully

Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
I downloaded GuiTest-1.3 (is that the same thing?) from CPAN. Unfortunaetly the install documentation makes too many assumptions. Can anyone tell me how to install it on Windows without installing a mass of additional software? TIA.
 
Theres a Win32::GUITest which should be more what you're after. The XS implementations are allegedly brilliant (because they're Pure Perl), and for that reason I can only assume the documentation doesn't have to be up to much. I had a brief glance at the dox you're talking about, and they looked sparse, wheras the Win32 one looks more like a traditional doc set.

HTH
Paul
PS Not trying to P*ss off the PP developers, but ...

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
What did I download? The documentation provides two ways to install. The first fails because I don't have 'nmake.' It seems this version is for Unix. The second requires installing more software which I prefer to avoid.
 

look for "Win32::GUITest", or "Win32 GUI"

.xs is the Pure Perl implementation which is supposed to be portable, and have no dependencies

Cheers
Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
If your perl install was from activestate, then you should have ppm. If this is the case, you can:

1) Open a command prompt
2) type ppm <return>
3) type install Win32-GuiTest <return>

This should install the package for you.

Else, you can do it through CPAN, but it is more involved.
 
I guess I am just totally confused. I looked for win32::guitest and got the same thing I just downloaded. Perhaps you would be kind enough to post the URL you are talking about.

I don't have activestate perl I have Indigo perl.
 
try typing 'IPM help' at a command prompt. (Indigo Package Manager)

I installed Activestate Python at one point, and it associated my ppd files with an installer program.. now I can just double-click on them, and it installs them in my perl path - might work for Indigo perl too. It just makes things a little easier. (at work I can't download modules with ppm because of the firewall)

I seem to remember coming across some perl code a while back that opened notepad.exe then typed out &quot;Welcome to perl&quot; or something like that... Is that the kind of thing you're looking for, or am I not getting it? If so, I'll poke around to see if I can find it again. I'm actually in need of something like that too for a project I'm working on.

-j
 
Dunno indigo perl, but theres' gotta be a command line to CPAN from there

anyway lookfor
Check out Barbie's links (missbarbell) on the FAQ (3 clicks over) for CPAN and PPM installs

HTH
Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
I've used Win32::GuiTest extensively at work for an after-hours process automation. The hard part is selecting which window you want. Straight from ASPN module documentation:

use Win32::GuiTest qw(FindWindowLike GetWindowText
SetForegroundWindow SendKeys);

$Win32::GuiTest::debug = 0; # Set to &quot;1&quot; to enable verbose mode
my @windows = FindWindowLike(0, &quot;^Microsoft Excel&quot;, &quot;^XLMAIN\$&quot;);
for (@windows) {
print &quot;$_>\t'&quot;, GetWindowText($_), &quot;'\n&quot;;
SetForegroundWindow($_);
SendKeys(&quot;%fn~a{TAB}b{TAB}{BS}{DOWN}&quot;);
}
 
Some code from my app:

system(&quot;t:\\tmwin\\dbutil.exe&quot;);
SendKeys(&quot;{PAUSE 5000}A{PAUSE 1000}<username/password combo>{ENTER}{PAUSE 1000}%C{PAUSE 1000}R{PAUSE 1000}%A{PAUSE 1000}{TAB 7}{SPACE}%N{TAB}{SPACE}{TAB}{SPACE}{ENTER}Y&quot;);
print &quot;Database fix&quot;;
Circle1a:
print &quot;.&quot;;
sleep 5;
$all=&quot;&quot;;
my @windows = FindWindowLike(0);
for (@windows) {$all=$all.GetWindowText($_)}
if ($all =~ /TeleMagic Database Fix/) {goto Circle1a}

I'm sure there is a more elegant way of doing it, but this kludge works for me.
 
Thanks top all that replied.

chazoid:

Thanks for the suggestion. I'll see if IPM is there but it will be a couple of days before I can get back to that.

PaulTEG:

Yes, that is what I have. It requires 'nmake' or PPM to install. Perhaps IPM will work if Indigo perl has it or something similar.
 
A change in plans, I was able to try it. This is a good news/bad news scenario. The good news is Indigo perl does indeed have an IPM command and I was apparently able to successfully install the package. The bad news is why I used the word 'apparently'. When I try to use FindWindowLike, I get the following error:

Can't load 'C:/OpenSA/perl/site/lib/auto/Win32/GuiTest/GuiTest.dll' for module Win32::GuiTest: load_file:One of the library files needed to run this application
cannot be found at C:/OpenSA/perl/lib/DynaLoader.pm line 229.

That path and file does exist so I have no clue why it cannot find it. Suggestions?
 
I'm really not sure what the problem is... Is the OpenSA dir the default installation path for IndigoPerl? Maybe it's not liking that even though it seems to be looking in the right place.. It's a long shot, but I guess it could have something to do with it.
 
Yes, that is the install path and the directory in the %path% variable.

I posted this as a new question since it is no longer appropriate for this thread. I'm hoping someone with expereince with Indigo perl will see it. I also wrote to the author but so far no response.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top