Autor Beitrag
LonghornUser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: Di 24.04.12 10:26 
Hallo,

ich habe schon ein bisschen recherchiert, um mein Problem zu lösen, komme aber nicht so recht weiter damit.

Und zwar möchte ich einen String an die aktuell fokussierte externe Anwendung senden (per Tastenshortcut). Prinzipiell sollte das ja mit SendMessage und GetFocus für den Handle des aktuellen Controls gehen. Leider funktioniert das z.B. im Firefox nicht. (Kann es sein, dass sich dieser gegen solche EIngriffe schützt?)

Habt ihr eine Idee, wie ich das möglichst so mache, dass es in *allen* Anwendungen funktioniert?

Danke!!

Ciao LHUser
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Di 24.04.12 10:57 
Sendkeys ?

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
rd3
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 24.04.12 12:38 
Ich hatte sowas schonmal rückwärts gemacht:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
function GetFocusedControlSelText: String;
var
  focusedHandle, activeWinHandle: HWND;
  focusedThreadID : DWORD;
  pc:PWideChar;
  str:String;
  i,lpos,fpos:integer;
begin
  i:=0;
  Windows.SetFocus(0);
  SetLengtH(str,65536);
  pc := PWideChar(stR);
  activeWinHandle := GetForegroundWindow;
  focusedThreadID := GetWindowThreadProcessID(activeWinHandle, nil) ;
  if AttachThreadInput(GetCurrentThreadID, focusedThreadID, true) then
  try
    focusedHandle := Windows.GetFocus;
    if focusedHandle <> 0 then
    begin
      i := SendMessage(focusedHandle, EM_GETSEL, 00);
      if( i > 0 ) then
      begin
        lpos := (i shr 16AND $FFFF;
        fpos := i and $FFFF;
        i := SendMessage(focusedHandle, WM_GETTEXT, 65536, Integer(pc));
        if( i <> 0 ) then
        begin
          result := copy(str,fpos+1,lpos-fpos);
        end;
      end;
      SetLength(str,i);
      result := str;
    end
  finally
    AttachThreadInput(GetCurrentThreadID, focusedThreadID, false) ;
  end;
end;
// s. auch: http://embarcadero.newsgroups.archived.at/public.delphi.nativeapi/201006/1006253692.html


War auch nicht sehr zuverlässig...

Weiterhin könntest Du über sendKeys() oder auch ggf. über die Zwischenablage, oder keybd_event gehen...