AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein GUI-Design mit VCL / FireMonkey / Common Controls Delphi Formfenster soll wenn es inaktiv ist auf eingabe reagieren

Formfenster soll wenn es inaktiv ist auf eingabe reagieren

Ein Thema von Axxus · begonnen am 4. Okt 2006 · letzter Beitrag vom 7. Okt 2006
Antwort Antwort
Seite 1 von 2  1 2   
Axxus

Registriert seit: 3. Okt 2006
212 Beiträge
 
Turbo Delphi für Win32
 
#1

Formfenster soll wenn es inaktiv ist auf eingabe reagieren

  Alt 4. Okt 2006, 22:02
Hi Delphianer

Gesucht hab ich schon aber nix gefunden

Also folgendes

Ich hab ein Programm das auf Eingaben reagieren soll selbst wenn es inaktiv ist

Blödes Beispiel jetzt aber zum Beispiel soll

das Programm im hintergrund laufen und ich zocke ien PC spiel und wenn ich auf 1 drücke macht es einen screenshot, wenn ich auf 2 drücke spielt es Musik ab wenn ich auf 3 drücke hält es die Musik auf ...

eben das ich nicht immer das Fenster wechseln muss wenn ich was außerhalb meines Spiels machen will

Axxus
Alexander Dietz
  Mit Zitat antworten Zitat
Thanatos81
(Gast)

n/a Beiträge
 
#2

Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier

  Alt 4. Okt 2006, 22:06
Was du suchst ist Hooking. Eine Suche nach Hier im Forum suchenHook, Hier im Forum suchenHooks oder eben Hier im Forum suchenHooking sollte dir schon weiterhelfen. Würde dir ja nen genaueren Hinweis geben, aber ich hab mich mit Hooking bisher selbst noch nicht beschäftigt ,-)
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#3

Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier

  Alt 4. Okt 2006, 22:16
Hier damit du siehst auf was du dich da einläßt!

Delphi-Quellcode:
library HookDLL;

uses
  Windows,
  Messages,
  SysUtils,
  Classes;

{$R *.res} 

var
  G_hHook : THandle;

//------------------------------------------------------------------------------
function MessageHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
  aMsg: ^tagMSG;
  aCDS: TCopyDataStruct;
  hWnd: THandle;
begin
  if (nCode < 0) then
    Result := CallNextHookEx(G_hHook, nCode, wParam, lParam)
  else
  begin
    aMsg := pointer(lParam);

    aCDS.dwData := 0;
    aCDS.cbData := SizeOf(tagMsg);
    aCDS.lpData := aMsg;

    if aMsg^.message = WM_MOUSEWHEEL then // !!!
    begin
      hWnd := FindWindow(nil, 'Form1');
      SendMessage(hWnd, WM_COPYDATA, 0, integer(@aCDS));
    end;
    if aMsg^.message = WM_LBUTTONDBLCLK then // !!!
    begin
      hWnd := FindWindow(nil, 'Form1');
      SendMessage(hWnd, WM_COPYDATA, 0, integer(@aCDS));
    end;
    Result := CallNextHookEx(G_hHook, nCode, wParam, lParam);
  end;
end;
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
function InstallHook(DWThreadID: DWORD): boolean; stdcall;
begin
  Result := False;

  if (G_hHook <> 0) then
  begin
    MessageBox(0, 'Hook already installed!', '', 0);
    Exit;
  end;

  G_hHook := SetWindowsHookEx(WH_GETMESSAGE, @MessageHookProc, GetModuleHandle('HookDLL.dll'), DWThreadID);

  Result := G_hHook <> 0;

  if Result then
     MessageBox(0, 'Hook successfully installed.', 'InstallHook', MB_ICONINFORMATION);
end;
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
procedure UnInstallHook; stdcall;
begin
  if (G_hHook <> 0) then
     UnhookWindowsHookEx(G_hHook);
end;
//------------------------------------------------------------------------------

exports
  InstallHook,
  UnInstallHook;

begin
  G_hHook := 0;
end.
Mußt du halt selber umstricken auf Tastatur Befehle.

Gruß
  Mit Zitat antworten Zitat
Axxus

Registriert seit: 3. Okt 2006
212 Beiträge
 
Turbo Delphi für Win32
 
#4

Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier

  Alt 4. Okt 2006, 22:20
ach du sch...e

OK ich schau aml ob ich damit was anfangen kann

Vielen Dank

Axxus
Alexander Dietz
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#5

Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier

  Alt 4. Okt 2006, 22:22
Hier noch ein Beispiel!

Copy/Paste

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    btnHook: TButton;
    edWndToHook: TEdit;
    lvMain: TListView;
    procedure btnHookClick(Sender: TObject);
  private
    { Private declarations }

  protected
    procedure _WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

  function InstallHook(DWThreadID: DWORD): boolean; stdcall external 'HookDLL.dll';

implementation

{$R *.dfm}

procedure TForm1.btnHookClick(Sender: TObject);


begin
  if not InstallHook(0) then // nicht dwThreadID übergeben, sondern 0, weil ALLE Applikationen gehookt werden sollen.
     raise Exception.Create('Error installing hook');

end;


procedure TForm1._WMCopyData(var Msg: TWMCopyData);
var
  aMsg: ^tagMsg;
begin
  aMsg := Msg.CopyDataStruct.lpData;

  with lvMain.Items.Add do
  begin
    Caption := IntToStr(aMsg^.time);
    SubItems.Add(IntToStr(aMsg^.message));
    SubItems.Add(IntToStr(aMsg^.wParam));
    SubItems.Add(IntToStr(aMsg^.lParam));
  end;
end;

end.
Unit1.dfm

Delphi-Quellcode:
object Form1: TForm1
  Left = 342
  Top = 107
  Width = 585
  Height = 263
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object btnHook: TButton
    Left = 8
    Top = 8
    Width = 97
    Height = 25
    Caption = 'Hook this window'
    TabOrder = 0
    OnClick = btnHookClick
  end
  object edWndToHook: TEdit
    Left = 112
    Top = 10
    Width = 321
    Height = 21
    TabOrder = 1
    Text = 'notepad'
  end
  object lvMain: TListView
    Left = 8
    Top = 40
    Width = 417
    Height = 177
    Columns = <
      item
        Caption = 'Time'
      end
      item
        Caption = 'Message'
        Width = 100
      end
      item
        Caption = 'wParam'
        Width = 100
      end
      item
        Caption = 'lParam'
        Width = 100
      end>
    TabOrder = 2
    ViewStyle = vsReport
  end
end
Gruß
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#6

Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier

  Alt 4. Okt 2006, 22:34
Noch eins !
das dürfte aber reichen...

http://assarbad.net/stuff/tutorials/hooks/
In Deutsch

Google läßt grüßen!

Achtung ! Du darfst aber Hooks nicht benutzen...
Könnte ja sein das du dem User etwas aufzwingst was er nicht möchte.
Hooks sollte man eigenlich nicht verwenden.
Verstehst du ?

gruß
  Mit Zitat antworten Zitat
Benutzerbild von Sunlight7
Sunlight7

Registriert seit: 17. Sep 2006
Ort: Sonnensystem, Zentral
1.522 Beiträge
 
Delphi 5 Standard
 
#7

Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier

  Alt 4. Okt 2006, 22:40
Wenn Dein Programm nur kleinigkeiten wie nen Schnappschuß machen soll, wären Hot-Keys der einfachere Weg!
Ich habe zB. auf dem Pause/Break nen Hot-Key, damit mein Player beginnt oder anhält, mit der Druck Taste sofortaufnahme vom TV, ...

Meinst Du so was?
Windows: Ja - Microsoft: Nein -> www.ReactOS.org
  Mit Zitat antworten Zitat
Axxus

Registriert seit: 3. Okt 2006
212 Beiträge
 
Turbo Delphi für Win32
 
#8

Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier

  Alt 5. Okt 2006, 14:23
So was mein ich gesucxht hab ich ja aber nix gefunden da ich nicht mehr usste wie so was heißt das mit dem Hock is glaub ich ziemlich kompliziert für mich ich versteh fa noch net mal wieso das eien beispielprogramm läuft obwohl in dem mian Quelltext überhaupt kein implenatiion und interfaceteil ist das mit dem HotKey müsste besser sein.

Das brauch ich aber nur wenn das Fenster auch inaktiv sein kann und trotzdem auf den Tastendruck reagiert und wenn ich in nem spiel drin bin und da was mit der Taste gemacht werden kann z.B. Empire Earth Kapitol C Bürger bauen trotzdem muss mein Programm im Hintergrund den Befehl ausführen

Edit// Ist es das???

Mist find wieder nix man bin ich unfähig kann mir einer mal en tut zum ertstellen eines HOtkeys geben

Axxus
Alexander Dietz
  Mit Zitat antworten Zitat
Benutzerbild von inherited
inherited

Registriert seit: 19. Dez 2005
Ort: Rosdorf
2.022 Beiträge
 
Turbo Delphi für Win32
 
#9

Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier

  Alt 5. Okt 2006, 15:17
BEUIÖÄÜ?
Könntest du dir angewöhnen, mit Punkt (.) und Komma (,) zu schreiben, ich musste deinen Beitrag 3 mal lesen, bevor ich ihn verstanden habe...
Schau dir mal
Delphi-Quellcode:
uses keyboard;
//[...]
if Keyboard.IsKeyDown(VK_UP) then
  beep;
an. Dann Piept der PC immer, wenn jemand Die Nach-oben-taste drückt^^
Nikolai Wyderka

SWIM SWIM HUNGRY!
Neuer Blog: hier!
  Mit Zitat antworten Zitat
Axxus

Registriert seit: 3. Okt 2006
212 Beiträge
 
Turbo Delphi für Win32
 
#10

Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier

  Alt 5. Okt 2006, 16:43
Sorry für die Räschtchaipund ^^
Aber du verstehst mein Problem nicht denn

Die Aktion die ausgeführt werden soll soll auch eintreten wenn das fenster nicht den Fokus hat und das geht ja nicht

Kann mir jmn helfen

Axxus
Alexander Dietz
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2   

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:13 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz