Link to home
Start Free TrialLog in
Avatar of Chipmunk77
Chipmunk77

asked on

Delphi Send Keys Shift End

I am using Delphi to create a virtual user that fills in a form in another application.  In this form, there are some cases where certain fields get filled in and other times where they do not.  I am trying to highlight any text in the field so I can write over it.  My initial idea was to do a shift_dn, end, shift_up - which is what works in the appliication (I have also been trying in word with the same results).  However, for some reason, it does not recognize the shift_dn with the end command.  If I try shift_dn, then a letter, it capitalizes it, so I know the shift_dn is working.  Is anyone aware of a special key combination to create the shift+end in another application?  The keys are all using the VK command - in another object, so they are using the basic functions, they just aren't responding to shift-end like I would expect.
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

hmm indeed sending input doesn't select text, try this:
var Selection: TSelection;
    h: THandle;
begin
  h := GetFocus;
  Selection.StartPos := 0;
  Selection.EndPos := MaxInt;
  SendMessage(h, EM_SETSEL, Selection.StartPos, Selection.EndPos);
  SendMessage(h, EM_SCROLLCARET, 0, 0);


ziolko.
Avatar of Chipmunk77
Chipmunk77

ASKER

No, thanks for the try though - I added 'SHFTEND=DOCUMENT2' to the script with the following code in the executable - but no luck....  

    else if (UpperCase(FMacro.Names[nLine]) = 'SHFTEND') then
    begin
      h := SendKeysMacro.HandleFromTitle(FindWindowTitle(FMacro.ValueFromIndex[nLine]));
      h := GetFocus;
      Selection.StartPos := 0;
      Selection.EndPos := MaxInt;
      SendMessage(h, EM_SETSEL, Selection.StartPos, Selection.EndPos);
      SendMessage(h, EM_SCROLLCARET, 0, 0);
    end


The program reads a bunch of lines from a script file and executes them - hence the else if  :-)

Any other ideas?  I'm stumped at this point....
h := SendKeysMacro.HandleFromTitle(FindWindowTitle(FMacro.ValueFromIndex[nLine]));
h := GetFocus;

use only one of those values:
SendKeysMacro.HandleFromTitle()
OR
GetFocus

ziolko.
Still no luck, I tried with each one individually.  I tried looking for some other options - do you know what VK_SELECT or VK_EXSEL do?  I thought maybe they might work, but I can't find a definition for either, other than the Select key and ExSel key...  

Thanks for your ideas, they are very much appreciated
>>Still no luck, I tried with each one individually

:/ then I'm out of ideas

>>do you know what VK_SELECT or VK_EXSEL
last time I saw keyboard with select and exsel keys was some some 8 yrs ago:)

ziolko.
Ideas :)

1) Send Ctrl+A if you want to select a single line, inside an editbox or a field.
2) If it is a multiline field get the lenght of the line you want to select ...
For example inside a memo the first line contains :
Length(Memo1.Lines[1])  ----> 11 characters...
~-~-~-~-~-~-~-~-~-~-~-~-~-
Send Shift down
For i:=0 to 10 do
begin
...
Send right arrow  //11 times...
Release right arrow
...
end;
Release Shift Down


Hope this will help :)
ASKER CERTIFIED SOLUTION
Avatar of dinilud
dinilud
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the info CodedK - that works great in word!  Unfortunately, it doesn't work in the actual app I was originally trying to write to  :-( , any ideas on what key combo it could be there - Ctrl-A doesn't work even with true keyboard input there.  I can't find anything in their help...  I know the Shift-end works from true keyboard input, but won't work through the send keys (I don't think the end recognizes the shift?)

Thanks again for the ideas everyone  
Thank you!  This works beautifully!
Thanks all!  It finally works  :-)

Thanks for all the great suggestions and help!