• SetWindowHookEx的复习


    #include <Windows.h>
    #include <iostream>
    
    using namespace std;
    
    HHOOK keyboardHook;
    
    LRESULT __stdcall KEYHookCallback(int nCode, WPARAM wParam, LPARAM lParam)
    {
        int num[] = { 0x41,0x42,0x43,0x44 ,0x45 ,0x46 ,0x47 ,0x48 ,0x49 ,0x4A ,0x4B ,0x4C ,0x4D ,0x4E ,0x4F,
                        0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,0x58,0x59,0x5A,0x20};
        const char *ch[] = { "A","B", "C", "D", "E", "F", "G", "H","I", "J", "K", "L", "M", "N",
                         "O","P", "Q", "R", "S", "T", "U" ,"V","W", "X", "Y", "Z"," "};
        if (nCode >= 0)
        {
            switch (wParam)
            {
            case WM_KEYDOWN:
            {
                HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
                DWORD written = 0;
                KBDLLHOOKSTRUCT* kbdStruct = (KBDLLHOOKSTRUCT*)lParam;
               
                if (stdOut == NULL || stdOut == INVALID_HANDLE_VALUE)
                {
                    cout << "error handle" << endl;
                    return 0;
                }
                POINT pntCurrentCursor;
                GetCursorPos(&pntCurrentCursor);
                HWND h = FindWindow("Notepad", NULL);
                HWND h2 = FindWindowEx(h, 0, "Edit", NULL);
                HWND h1 = WindowFromPoint(pntCurrentCursor);            
                if(h1 == h2)
                {                                                                 
                    for (int i = 0; i < sizeof(num) / sizeof(int); i++)
                    {
                        if (kbdStruct->vkCode == num[i])
                        {
                            WriteConsole(stdOut, ch[i], 1, &written, NULL);
                        }
                    }
                }                    
                return 1;
            }            
            }
        }
        return CallNextHookEx(keyboardHook, nCode, wParam, lParam);
    }
    
    void SetHook()
    {
        if (!(keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KEYHookCallback, NULL, 0)))
        {
            cout << "Failed to install keyboardHook hook!" << endl;
        }
    }
    
    void ReleaseHook()
    {
        UnhookWindowsHookEx(keyboardHook);
    }
    
    int main()
    {
        SetHook();
        MSG msg;
    
        while (GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        ReleaseHook();
        return msg.wParam;
    }
  • 相关阅读:
    centos安装MySQL5.7
    centos搭建ftp服务器的方法
    centos 7 卸载 mariadb 的正确命令
    MySQL5.7关于密码二三事
    第四次:渗透练习,xss学习
    第三次靶场练习:通过抓包,绕过内部限制
    第二次靶场练习:cookie注入
    第一次靶场练习:SQL注入(1)
    Linux用户和组管理
    Linux基础命令(三)
  • 原文地址:https://www.cnblogs.com/strive-sun/p/12627057.html
Copyright © 2020-2023  润新知