Flying_whale
Flying_whale

Reputation: 377

unable to send shift-end with Win32::GuiTest

I would need to automate some keyboard entries inside my perl script. For this, I use Win32::GuiTest module. This works fine for all entries I need except for shift-end.

Here's what I send

Win32::GuiTest::SendKeys("+{END}");

but it seems that it only takes the {END}.

The weird thing is that

Win32::GuiTest::SendKeys("+(some text)");

works fine and sends SOME TEXT

In fact, I am unable to do +{} commands, it always take only the key inside the {}

On the other hand, commands with ^ (ctrl) or % (alt) work fine for example Win32::GuiTest::SendKeys("%{F4}") closes the window

does anybody would know why?

Thanks :)

Upvotes: 2

Views: 346

Answers (1)

Andreas Kneissl
Andreas Kneissl

Reputation: 11

Late answer, anyway, maybe it is of help to somebody...

Shift{foo} commands like Shift{End} need to be performed with low-level keybd_event via the SendRawKey wrapper. So this is what you are looking for:

    SendRawKey(VK_LSHIFT, KEYEVENTF_EXTENDEDKEY);
    SendKeys('{END}');
    SendRawKey(VK_RSHIFT, KEYEVENTF_KEYUP);
    SendRawKey(VK_LSHIFT, KEYEVENTF_KEYUP);

Full sample (copies a complete line into the clipboard):

use warnings;
use strict;

use Win32::Clipboard;
use Win32::GuiTest qw (:ALL);   # Win32-GuiTest-1.63 used

print "place cursor now...\n"; sleep(5); print get_line();

sub get_line {

    Win32::Clipboard()->Empty();

    SendKeys('{HOME}');
    SendRawKey(VK_LSHIFT, KEYEVENTF_EXTENDEDKEY);
    SendKeys('{END}');
    SendRawKey(VK_RSHIFT, KEYEVENTF_KEYUP);
    SendRawKey(VK_LSHIFT, KEYEVENTF_KEYUP);

    SendKeys('^c');
    return Win32::Clipboard()->GetText();
}

Upvotes: 1

Related Questions