Hallo meine Lieben!
Ich hoffe, ihr könnt mir helfen:
Ich bin gerade dabei, einen Tastatur-Hook zu schreiben, bzw. meinen dynamischer zu gestalten.
User sollen die Möglichkeit haben, über eine .pas-Datei selbst bestimmen zu können, was wann passiert wenn welche Taste gedrückt wurde.
Für das Einlesen & Compilen habe ich mir DWS-II rausgesucht und schon ein bissl rumprobiert. Mein Problem ist nun, dass sich nix, aber auch wirklich NIX tut, wenn ich eine Taste drücke.
Könnte vllt. jmd. das ganze mal Querlesen und mich auf evtl. auftretende Fehlerquellen aufmerksam machen?
Hier mal der Quelltext:
.exe-Datei:
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:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient;
type TForm1 = class(TForm) udp: TIdUDPClient; Label5: TLabel; Label6: TLabel; Button3: TButton; Label7: TLabel; Label1: TLabel; procedure FormDestroy(Sender: TObject); procedure Button3Click(Sender: TObject); private public end;
var Form1: TForm1; ip: string; port: integer;
function InstallHook(Hwnd: Cardinal): Boolean; stdcall; external 'shortcuts.dll'; function UninstallHook: Boolean; stdcall; external 'shortcuts.dll';
implementation
{$R *.dfm}
procedure TForm1.FormDestroy(Sender: TObject); begin UnInstallHook; end;
procedure TForm1.Button3Click(Sender: TObject); begin InstallHook(Handle); end;
end. |
.dll-Datei:
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:
| library shortcuts_beta;
uses Windows, Messages, Classes, SysUtils, dialogs, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient, mmsystem, dws2Comp, dws2VCLGUIFunctions, dws2Exprs, Spin;
var HookHandle: Cardinal = 0; WindowHandle: Cardinal = 0; DelphiWebScriptII: TDelphiWebScriptII; sl: TStringList;
function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; var x:integer; prog: TProgram; to_say: String; begin Result := CallNextHookEx(HookHandle, nCode, wParam, lParam); case nCode < 0 of TRUE: exit; FALSE: begin DelphiWebScriptII:= TDelphiWebScriptII.Create(nil);
sl := TStringList.Create; sl.LoadFromFile('keys.pas'); prog := DelphiWebScriptII.Compile(sl.Text); prog.BeginProgram; to_say := prog.Info.Func['get_keys'].Call.Value;
if Prog.Msgs.HasCompilerErrors then for x := 0 to Prog.Msgs.Count - 1 do ShowMessage(Prog.Msgs[x].AsInfo); prog.EndProgram;
showmessage(to_say); end; end;
end;
function InstallHook(Hwnd: Cardinal): Boolean; stdcall; begin Result := False; if HookHandle = 0 then begin HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, HInstance, 0); WindowHandle := Hwnd; Result := TRUE; end; end;
function UninstallHook: Boolean; stdcall; begin Result := UnhookWindowsHookEx(HookHandle); HookHandle := 0; end;
exports InstallHook, UninstallHook; end. |
.pas-Datei:
Delphi-Quelltext
1: 2: 3: 4: 5: 6:
| function get_keys(wParam: WPARAM; lParam: LPARAM):String; begin if wParam = VK_F12 then if (lParam and (1 SHL 31) <> 0) then begin result:='test!'; end; |
Ich bedanke mich jetzt schon für Eure Mühen
Gruß
Friedemann
Moderiert von
jasocul: Code- durch Delphi-Tags ersetzt