unit UKeyHookUsingDll;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Timer1: TTimer;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ Functions prototypes for the hook dll }
type
TGetHookRecPointer = function: pointer stdcall;
TStartKeyBoardHook = procedure stdcall;
TStopKeyBoardHook = procedure stdcall;
{ The record type filled in by the hook dll }
THookRec = packed record
TheHookHandle: HHOOK;
TheAppWinHandle: HWND;
TheCtrlWinHandle: HWND;
TheKeyCount: DWORD;
end;
{ A pointer type to the hook record }
PHookRec = ^THookRec;
var
hHookLib: THANDLE; { A handle to the hook dll }
GetHookRecPointer: TGetHookRecPointer; { Function pointer }
StartKeyBoardHook: TStartKeyBoardHook; { Function pointer }
StopKeyBoardHook: TStopKeyBoardHook; { Function pointer }
LibLoadSuccess: bool; { If the hook lib was successfully loaded }
lpHookRec: PHookRec; { A pointer to the hook record }
EnterKeyCount: DWORD; { An internal count of the Enter Key }
procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
{ Process message sent from hook dll and display }
{ number of time the enter key was pressed }
if (Key = 0) then begin
Inc(EnterKeyCount);
Label2.Caption := IntToStr(EnterKeyCount) + ' Enter Keys Logged';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{ Set our initial variables }
Timer1.Enabled := FALSE;
Timer1.Interval := 1000;
Label1.Caption := '0 Keys Logged';
Label2.Caption := '0 Enter Keys Logged';
EnterKeyCount := 0;
lpHookRec := NIL;
LibLoadSuccess := FALSE;
@GetHookRecPointer := NIL;
@StartKeyBoardHook := NIL;
@StopKeyBoardHook := NIL;
{ Try to load the hook dll }
hHookLib := LoadLibrary('THEHOOK.DLL');
{ If the hook dll was loaded successfully }
if hHookLib <> 0 then begin
{ Get the function addresses }
@GetHookRecPointer := GetProcAddress(hHookLib, 'GETHOOKRECPOINTER');
@StartKeyBoardHook := GetProcAddress(hHookLib, 'STARTKEYBOARDHOOK');
@StopKeyBoardHook := GetProcAddress(hHookLib, 'STOPKEYBOARDHOOK');
{ Did we find all the functions we need? }
if ((@GetHookRecPointer <> NIL) AND (@StartKeyBoardHook <> NIL) AND (@StopKeyBoardHook <> NIL)) then begin
LibLoadSuccess := TRUE;
{ Get a pointer to the hook record }
lpHookRec := GetHookRecPointer;
{ Were we successfull in getting a ponter to the hook record }
if (lpHookRec <> nil) then begin
{ Fill in our portion of the hook record }
lpHookRec^.TheHookHandle := 0;
lpHookRec^.TheCtrlWinHandle := Button1.Handle;
lpHookRec^.TheKeyCount := 0;
{ Start the keyboard hook }
StartKeyBoardHook;
{ Start the timer if the hook was successfully set }
if (lpHookRec^.TheHookHandle <> 0) then begin
Timer1.Enabled := TRUE;
end;
end;
end else begin
{ We failed to find all the functions we need }
FreeLibrary(hHookLib);
hHookLib := 0;
@GetHookRecPointer := NIL;
@StartKeyBoardHook := NIL;
@StopKeyBoardHook := NIL;
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{ Did we load the dll successfully? }
if (LibLoadSuccess = TRUE) then begin
{ Did we sucessfully get a pointer to the hook record? }
if (lpHookRec <> nil) then begin
{ Did the hook get set? }
if (lpHookRec^.TheHookHandle <> 0) then begin
Timer1.Enabled := FALSE;
StopKeyBoardHook;
end;
end;
{ Free the hook dll }
FreeLibrary(hHookLib);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
{ Display the number of keystrokes logged }
Label1.Caption := IntToStr(lpHookRec^.TheKeyCount) + ' Keys Logged';
end;
end.
2012년 11월 13일 화요일
피드 구독하기:
댓글 (Atom)
델파이 12.1이냐 11.3이냐?
델파이가 12.1이 나왔습니다. 혹시 11.3버전의 커뮤니티버전이 필요하시는분이 있을 수 있을 것 같아 https://altd.embarcadero.com/.../RADStudio_11_3_esd_28... 와 이것 찾느랴 엄청고생함.
-
윈도우10에 있는 음성 녹음기는 간단하게 녹음 할 때 간편하고 좋다. 곰 녹음기를 사용하면 오늘기준으로 CPU 점유율이 35% 이상 올라가 맥의 팬이 돌아간다. 윈10의 음성녹음기는 좋은 데 저장 폴더가 디폴트로 되어 있어 사용하기 불편하다. ...
-
클라이언트가 HTTP프로토콜을 이용해서 서버에 무언가를 전달할 때 Get 이나 Post가 사용됩니다. GET은 주소줄에 값이 ?뒤에 쌍으로 이어붙고 여러개일 경우에는 & 으로 반복하고, POST는 숨겨져서(body안에) 보내집니다. GET...
-
일단은 Python 사이트에가서 dmg 파일을 다운받아 설치합니다. m1 프로세서일경우에는 아래에 있는 파일이겠죠. 터미널을 열어 파이썬의 위치를 확인합니다. 파이썬3의 위치로 이동합니다. [cd /usr/local/bin] 파인더를 엽니다. [...
댓글 없음:
댓글 쓰기