Autor Beitrag
Gerhard
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Do 02.10.03 21:28 
Hi,

ich möchte von einem Delphi-Programm an ein anderes Programm (Winamp) eine Tastenkombination (z.B. Alt d) zwecks Programmsteuerung senden. Gibt es eine einfach Möglichkeit?

Danke Gerhard
GruppeCN
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 322



BeitragVerfasst: Do 02.10.03 22:18 
Die Frage wurde schon öfter diskutiert, eine Lösung wurde glaube ich noch nicht gefunden... Das große Problem ist eigentlich einen Tastendruck zu simulieren !

_________________
Warum sind die Sachen, die du suchst, immer da, wo du zuletzt nachsiehst?
Weil du aufhörst zu suchen, wenn du sie gefunden hast.
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Fr 03.10.03 09:26 
willst du das allgemein wissen oder speziell in bezug auf winamp. da kannst du nämlich die winamp API nutzen die dir so ziemlich alle funktionen in winamp offenlegt.

_________________
In the beginning was the word.
And the word was content-type: text/plain.
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Fr 03.10.03 12:39 
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:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
{****************************************************}
{              SendKeys Unit for Delphi 32           }
{    Copyright (c) 1999 by Borut Batagelj (Slovenia) }
{                       Aleksey Kuznetsov (Ukraine)  }
{            Home Page: www.utilmind.com             }
{            E-Mail: info@utilmind.com               }
{****************************************************}

unit SendKeys;

interface

uses
  Windows, SysUtils;

const
  SK_BKSP = #8;
  SK_TAB = #9;
  SK_ENTER = #13;
  SK_ESC = #27;
  SK_ADD = #107;
  SK_SUB = #109;
  SK_F1 = #228;
  SK_F2 = #229;
  SK_F3 = #230;
  SK_F4 = #231;
  SK_F5 = #232;
  SK_F6 = #233;
  SK_F7 = #234;
  SK_F8 = #235;
  SK_F9 = #236;
  SK_F10 = #237;
  SK_F11 = #238;
  SK_F12 = #239;
  SK_HOME = #240;
  SK_END = #241;
  SK_UP = #242;
  SK_DOWN = #243;
  SK_LEFT = #244;
  SK_RIGHT = #245;
  SK_PGUP = #246;
  SK_PGDN = #247;
  SK_INS = #248;
  SK_DEL = #249;
  SK_SHIFT_DN = #250;
  SK_SHIFT_UP = #251;
  SK_CTRL_DN = #252;
  SK_CTRL_UP = #253;
  SK_ALT_DN = #254;
  SK_ALT_UP = #255;

procedure SendKeyString(Text: String);
procedure SendKeysToTitle(WindowTitle: String; Text: String);
procedure SendKeysToHandle(WindowHandle: hWnd; Text: String);
procedure MakeWindowActive(wHandle: hWnd);
function GetHandleFromWindowTitle(TitleText: String): hWnd;

implementation

procedure SendKeyString(Text: String);
var
   i: Integer;
   Shift: Boolean;
   vk, ScanCode: Word;
   ch: Char;
   c, s: Byte;
const
   vk_keys: Array[0..9of Byte =
      (VK_HOME, VK_END, VK_UP, VK_DOWN, VK_LEFT,
       VK_RIGHT, VK_PRIOR, VK_NEXT, VK_INSERT, VK_DELETE);
   vk_shft: Array[0..2of Byte = (VK_SHIFT, VK_CONTROL, VK_MENU);
   flags: Array[False..True] of Integer = (KEYEVENTF_KEYUP, 0);
begin
   Shift := False;
   for i := 1 to Length(Text) do
    begin
     ch := Text[i];
     if ch >= #250 then
      begin
       s := Ord(ch) - 250;
       Shift := not Odd(s);
       c := vk_shft[s shr 1];
       ScanCode := MapVirtualKey(c,0);
       Keybd_Event(c, Scancode, Flags[shift], 0);
      end
     else
      begin
       vk := 0;
       if ch >= #240 then
        c := vk_keys[Ord(ch) - 240]
       else
        if ch >= #228 then {228 (F1) => $70 (vk_F1)}
         c := Ord(ch) - 116
        else
         if ch < #110 then
          c := Ord(ch)
         else
          begin
           vk := VkKeyScan(ch);
           c := LoByte(vk);
          end;

       ScanCode := MapVirtualKey(c,0);
       if not Shift and (Hi(vk) > 0then { $2A = scancode of VK_SHIFT }
        Keybd_Event(VK_SHIFT, $2A00);
       Keybd_Event(c,scancode, 00);
       Keybd_Event(c,scancode, KEYEVENTF_KEYUP, 0);
       if not Shift and (Hi(vk) > 0then
        Keybd_Event(VK_SHIFT, $2A, KEYEVENTF_KEYUP, 0);
      end;
    end;
end;

procedure MakeWindowActive(wHandle: hWnd);
begin
  if IsIconic(wHandle) then
   ShowWindow(wHandle, SW_RESTORE)
  else
   BringWindowToTop(wHandle);
end;

function GetHandleFromWindowTitle(TitleText: String): hWnd;
var
  StrBuf: Array[0..$FFof Char;
begin
  Result := FindWindow(PChar(0), StrPCopy(StrBuf, TitleText));
end;

procedure SendKeysToTitle(WindowTitle: String; Text: String);
var
  Window: hWnd;
begin
  Window := GetHandleFromWindowTitle(WindowTitle);
  MakeWindowActive(Window);
  SendKeyString(Text);
end;

procedure SendKeysToHandle(WindowHandle: hWnd; Text: String);
begin
  MakeWindowActive(WindowHandle);
  SendKeyString(Text);
end;

end.
Gerhard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Fr 03.10.03 17:50 
Danke für die Hinweise
und den Sourcetext!

Zur Frage Winamp:
Ich möchte Winamp mit meinem Programm steuern, wo gibts die Winamp-api?

Gruß Gerhard
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Fr 03.10.03 18:01 
guck mal hier nach:

www.winamp.com/nsdn/
DaFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189



BeitragVerfasst: Fr 03.10.03 19:17 
Hi Gerhard,

Gerhard hat folgendes geschrieben:

ich möchte von einem Delphi-Programm an ein anderes Programm (Winamp) eine Tastenkombination (z.B. Alt d) zwecks Programmsteuerung senden.


darf ich wissen, was Du steuern möchtest?

Gruß,
Markus
Gerhard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Sa 04.10.03 13:14 
Hi Markus,
mit meinem Programm wähle ich MPs aus, welche ich zwecks abspielen an Winamp übergebe!

Gruß Gerhard
DaFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189



BeitragVerfasst: Sa 04.10.03 14:04 
Hi Gerhard,

dann würde ich nach diesen beiden Hilfestellungen vorgehen:

www.winamp.com/nsdn/...2x/dev/sdk/api.jhtml
www.delphi-forum.de/viewtopic.php?t=12252

Nämlich indem Du einfach die Dateien per ShellExecute (mit Parameter ADD) zur Playlist hinzufügst.

Gruß,
Markus
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Sa 04.10.03 15:27 
und wie soll dann löschen funktionieren??
DaFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189



BeitragVerfasst: Sa 04.10.03 16:26 
Hallo,

ich habe zwar in diesem Thread bisher nichts von Löschen gelesen, aber daran soll es nicht scheitern:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
  procedure RemoveWinampPlayListEntry(Index: Integer);
  const
    IPC_PE_DELETEINDEX = 104;
    WM_WA_IPC = WM_USER;
  var
    hWndWinamp: hWnd;
    hWndWinampPlayList: hWnd;
  begin
    hWndWinamp := FindWindow(PChar('Winamp v1.x'), nil);
    hWndWinampPlayList := FindWindow(PChar('Winamp PE'), nil);
    if (Index < 0then Index := SendMessage(hWndWinamp, WM_USER, 0125);
    SendMessage(hWndWinampPlayList, WM_WA_IPC, IPC_PE_DELETEINDEX, Index);
  end;


Kurze Erklärung: Index ist die Position des Eintrags in der Playlist, der gelöscht werden soll (beginnend bei 0). Ist Index -1, so wird der Titel von der Playlist entfernt, der gerade abgespielt wird.

Gruß,
Markus