Autor Beitrag
JustusJonas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Di 22.03.05 10:36 
Hallo Leute,

ich möchte gerne ein NumPad für unsere Tablet PCs programmieren.
Dabei soll bei einem Tastendruck an das zuvor aktive Fenster die jeweilige Taste übergeben werden.

Leider funktioniert meine Funktion nicht so ganz.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var  W : HWnd;
begin
   W := GetForeGroundWindow;
   if W <> 0 then
   begin
     PostMessage(GetForeGroundWindow, wm_KeyDown, VK_NUMPAD1,0);
     PostMessage(GetForeGroundWindow, wm_KeyUp, VK_NUMPAD1,0);
   end;
end;


Kann mir jemand sagen, was ich falsch gemacht habe?
Wenn ich auf den Button klicke passiert einfach gar nichts! :(

Greetz
Jailbird
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 127

Windows XP Pro SP2
Delphi 7 Professional
BeitragVerfasst: Di 22.03.05 10:43 
probier mal sendmessage anstatt postmessage
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Di 22.03.05 11:04 
Welches Fenster ist denn W? Dein Numpad muss dich aktiv sein, wenn du eine "Taste" drücken willst. Dann schickst du die Message aber an das Numpad. Oder sieht das in diesem Ausschnitt nur so aus?
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Di 22.03.05 12:50 
user profile iconwdbee hat folgendes geschrieben:
Welches Fenster ist denn W? Dein Numpad muss dich aktiv sein, wenn du eine "Taste" drücken willst. Dann schickst du die Message aber an das Numpad. Oder sieht das in diesem Ausschnitt nur so aus?


Ich glaube genau das ist mein Problem.
Wie bekomme ich raus, welches Fenster aktiv war, bevor jemand den Button meiner Form gedrückt hat und somit meine Form das aktive Fenster ist!?

Greetz
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Di 22.03.05 12:55 
Ich glaube nicht, dass das so einfach möglich ist. Was geht, ist dass du ein oder mehrere bestimmte Fenster ermittelst. Wie das geht steht u.a. hier in verschiedenen Threads.
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mi 23.03.05 14:18 
user profile iconwdbee hat folgendes geschrieben:
Ich glaube nicht, dass das so einfach möglich ist. Was geht, ist dass du ein oder mehrere bestimmte Fenster ermittelst. Wie das geht steht u.a. hier in verschiedenen Threads.


Irgendwie muss das doch gehen....gibt doch auch schon einige solcher Softwaretastaturen!?

Greetz
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Do 24.03.05 16:06 
Hab jetzt eine andere Idee:

Ich mach einfach einen Timer und in jedem TimerEvent lese ich das aktuelle Fenster aus.
Wenn es sich dabei nicht um meines handelt speicher ich es und beim Klick auf den Button sende ich einen Buchstaben an das vorherige Fenster.
Leider passiert in meinem Programm bei dem Klick auf meinen Button überhaupt nichts! :( Jemand eine Idee wieso?


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var
   LastActiveWindow: HWND;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
if GetForegroundWindow <> Form1.Handle
  then LastActiveWindow := GetForegroundWindow; 
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetForegroundWindow(LastActiveWindow);
end;


Greetz