AutomateWithPerl has asked for the wisdom of the Perl Monks concerning the following question:

We are all familiar with using the CNTRL button and mouse clicks to select multiple items in a list box. Especially good for non-contiguous selections.

I ran into problems recently trying to automate this very series of actions with Perl. I use Win32:GuiTest and similar modules to automate proprietary company software.

Problems:

- You cannot use SendKeys() and mouse controls like SendMouse() at the same time.

- You cannot use SendKeys() to "hold down" the Control key while you do other things.

The solution was to have my test script call another script, which will "hold down" the Control key while doing the click at the same time:

system 1, ".\\HoldControlKey.pl"; sleep 4; &SingleClick( 200, 245 ); sleep 7;

The system call will run the other script and continue execution of the calling script. Here is the code from HoldControlKey.pl:

use Win32::GuiTest qw(:ALL :SW ); sleep 2; SendKeys( "^(1111111111)", 500 );

The trick here is to press Control-1 repeatedly (which does nothing to the display), with a 1/2 second between each press of '1', but the Control key is held down. I had to adjust the 'sleep's to get the timing just right, but the solution worked.

Replies are listed 'Best First'.
Re: Control+Mouse clicks to select items
by BrowserUk (Patriarch) on Mar 15, 2011 at 05:05 UTC

    Have you tried using SendRawKey()? Something like this might work:

    SendRawKey( VK_CONTROL, 0 ); ## Control key down SendMouse( ... ); SendMouse( ... ): SendRawKey( VK_CONTROL, KEYEVENTF_KEYUP ); ## Control key up

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Control+Mouse clicks to select items
by Anonymous Monk on Mar 15, 2011 at 07:35 UTC
    Could have saved yourself some grief by reading http://www.piotrkaluski.com/files/winguitest/docs/winguitest.html and using WinSpy or Win32-GuiTest/ Recorder/Win32GuiTest.exe

    This was recorded in a cmd.exe window in QuickEdit/Insert mode, left mouse down + drag to select some text, right click to copy and right click to paste; I trimmed a bunch of MouseMoveAbsPix calls and inserted sleep

    #!/usr/bin/perl ## Initially generated by Win32-GuiTest Recorder (v1.03) ## Pragmas/Directives use strict; use warnings; ## Imports use Win32::GuiTest qw/:ALL/; $Win32::GuiTest::debug = 0; # Set to "1" to enable debug output. ## Main/Core SendRawKey(VK_LCONTROL, KEYEVENTF_EXTENDEDKEY); MouseMoveAbsPix(325, 279); SendMouse('{LEFTDOWN}'); MouseMoveAbsPix(362, 283); SendRawKey(VK_LCONTROL, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP); MouseMoveAbsPix(362, 283); SendMouse('{LEFTUP}'); sleep 1; SendMouse('{RIGHTCLICK}'); SendMouse('{RIGHTCLICK}'); __END__