#include
#include
#include #pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
HHOOK hKeyHook;
char Keyx[1024]; // 1K Byte
int i;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
hKeyHook=0;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK KeyHook(int iCode, WPARAM wParam, LPARAM lParam)
{
int j; Keyx[i] = wParam; // 這一行好像沒有作用,當我存檔時Keyx[]都是空的.
i ; if(iCode < 0)
CallNextHookEx(hKeyHook, iCode, wParam, lParam);
for(j=0;j<50000;j )
; }
//---------------------------------------------------------------------------
void __fastcall TForm1::BeginClick(TObject *Sender)
{
i =0;
hKeyHook=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyHook,HInstance,0);
}
//--------------------------------------------------------------------------- void __fastcall TForm1::ExitClick(TObject *Sender)
{
UnhookWindowsHookEx(hKeyHook); // Uninstall key hook
hKeyHook=0;
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender)
{
Form1->Key->Lines->Clear(); }
//--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender)
{
int Fhandle; if((Fhandle = creat("c:\\text.txt", S_IREAD | S_IWRITE)) != -1)
write(Fhandle, Keyx, i);
close(Fhandle); }
//---------------------------------------------------------------------------