• windows 键盘全局钩子


    // HookapiTest.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    
    using namespace std;
    
    HHOOK keyboardHook = 0;
    
    LRESULT CALLBACK HookCallback(int code, WPARAM wParam, LPARAM lParam)
    {
        KBDLLHOOKSTRUCT *ks = (KBDLLHOOKSTRUCT*)lParam;
        if(ks->vkCode == 'A')
        {
            cout << "A键拦截了!" << endl;
            return 1;
        }
        return CallNextHookEx(0, code, wParam, lParam);
    }
    
    int main()
    {
        keyboardHook = SetWindowsHookExA(WH_KEYBOARD_LL, HookCallback, GetModuleHandleA(0), 0);
    
        if (keyboardHook == 0)
        {
            cout << "键盘钩子挂失败了!" << endl;
            return -1;
        }
    
        cout << "钩子挂好了!" << endl;
    
    
        MSG msg;
    
        while(1)
        {
            if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
            {
                TranslateMessage(&msg);
                DispatchMessageW(&msg);
            }
            else
                Sleep(0);    //避免CPU全负载运行
        }
    
        UnhookWindowsHookEx(keyboardHook);
    
        cout << "正常结束!" << endl;
    
        return 0;
    }
  • 相关阅读:
    白话机器学习
    Intersecting Lines POJ
    Segments POJ
    Toy Storage POJ
    TOYS POJ
    2019CCPC秦皇岛赛区1004 Decimal
    Django 基本使用
    HTML页面布局
    微擎上传视频,音频,图片提示格式不支持
    微擎应用名称图标的修改
  • 原文地址:https://www.cnblogs.com/xuandi/p/7072714.html
Copyright © 2020-2023  润新知