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.
Chipmunk77Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ziolkoCommented:
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.
0
Chipmunk77Author Commented:
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....
0
ziolkoCommented:
h := SendKeysMacro.HandleFromTitle(FindWindowTitle(FMacro.ValueFromIndex[nLine]));
h := GetFocus;

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

ziolko.
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Chipmunk77Author Commented:
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
0
ziolkoCommented:
>>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.
0
CodedKCommented:
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 :)
0
diniludCommented:
procedure SendShiftEnd;
var
  KeyInputs: array of TInput;
  KeyInputCount: Integer;

procedure KeybdInput(VKey: Byte; Flags: DWORD);
  begin
    Inc(KeyInputCount);
    SetLength(KeyInputs, KeyInputCount);
    KeyInputs[KeyInputCount - 1].Itype := INPUT_KEYBOARD;
    with  KeyInputs[KeyInputCount - 1].ki do
    begin
      wVk := VKey;
      wScan := MapVirtualKey(wVk, 0);
      dwFlags := KEYEVENTF_EXTENDEDKEY;
      dwFlags := Flags or dwFlags;
      time := 0;
      dwExtraInfo := 0;
    end;
  end;
begin
  KeybdInput(VK_SHIFT, 0);                // shift
  KeybdInput(VK_END, 0);                 // end
  KeybdInput(VK_END, KEYEVENTF_KEYUP);   // end
  KeybdInput(VK_SHIFT, KEYEVENTF_KEYUP); // shift
  SendInput(KeyInputCount, KeyInputs[0], SizeOf(KeyInputs[0]));
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  ShellExecute(Handle,'open','Notepad',nil,nil,SW_NORMAL);
  Sleep(1000);
  NewApp:=GetForegroundWindow;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   SetForegroundWindow(NewApp);
   SendShiftEnd;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chipmunk77Author Commented:
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  
0
Chipmunk77Author Commented:
Thank you!  This works beautifully!
0
Chipmunk77Author Commented:
Thanks all!  It finally works  :-)

Thanks for all the great suggestions and help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.