![]() |
Formfenster soll wenn es inaktiv ist auf eingabe reagieren
Hi Delphianer :hi:
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 :dancer: Axxus :dancer2: |
Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier
|
Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier
Hier damit du siehst auf was du dich da einläßt!
Delphi-Quellcode:
Mußt du halt selber umstricken auf Tastatur Befehle.
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. Gruß |
Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier
ach du sch...e
OK ich schau aml ob ich damit was anfangen kann Vielen Dank :!: :!: :!: Axxus |
Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier
Hier noch ein Beispiel!
Copy/Paste
Delphi-Quellcode:
Unit1.dfm
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.
Delphi-Quellcode:
Gruß
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 |
Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier
Noch eins !
das dürfte aber reichen... ![]() 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ß |
Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier
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? |
Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier
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 :wall: Axxus |
Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier
:shock: 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:
an. Dann Piept der PC immer, wenn jemand Die Nach-oben-taste drückt^^
uses keyboard;
//[...] if Keyboard.IsKeyDown(VK_UP) then beep; |
Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier
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 |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:30 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz