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)
tensorflow gpu 사용하기에서
tensorflow 설치시 주의해야 한다. # Anything above 2.10 is not supported on the GPU on Windows Native python - m pip install "tensorflow<2.11...
-
클라이언트가 HTTP프로토콜을 이용해서 서버에 무언가를 전달할 때 Get 이나 Post가 사용됩니다. GET은 주소줄에 값이 ?뒤에 쌍으로 이어붙고 여러개일 경우에는 & 으로 반복하고, POST는 숨겨져서(body안에) 보내집니다. GET...
-
1. 휴대폰 앱을 이용하여 키움증권 비대면 계좌를 만듭니다. 2. Open Api 사용신청을 합니다. 3. 모의투자 신청을 합니다. 4. 멀티접속을 신청합니다. 5. 키움증권에 접속하여 키움 Open Api+ 를 다운 받아 설치한다. 6. 키...
-
윈도우10에 있는 음성 녹음기는 간단하게 녹음 할 때 간편하고 좋다. 곰 녹음기를 사용하면 오늘기준으로 CPU 점유율이 35% 이상 올라가 맥의 팬이 돌아간다. 윈10의 음성녹음기는 좋은 데 저장 폴더가 디폴트로 되어 있어 사용하기 불편하다. ...
댓글 없음:
댓글 쓰기