zoukankan      html  css  js  c++  java
  • DELPHI实现键盘勾子

    //调用键盘钩子,屏蔽功能键
    function keyHookProc(nCode: Integer; LWParam: WPARAM; LLParam: LPARAM): LRESULT; stdcall; 
      
    var
      hHk :HHOOK;
      
    //创建勾子
    hHk:= SetWindowsHookEx(13, @keyHookProc, HInstance, 0);
    
    function keyHookProc(nCode: Integer; LWParam: WPARAM; LLParam: LPARAM): LRESULT;//调用键盘钩子,屏蔽功能键
    var
      p: PKBDLLHOOKSTRUCT;
      y: integer;
    begin
       if nCode < 0 then
      begin
        Result:= CallNextHookEx(hHk, nCode, LWParam, LLParam);
        Exit;
      end
      else
      begin
        y := 0;
        case LWParam of
          WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP,WM_SYSKEYUP:
          begin
            p:= PKBDLLHOOKSTRUCT(LLParam);
            if p^.vkCode = VK_LWIN then y:= 1
            else if p^.vkCode = VK_RWIN then y:= 1
            else if (p.vkCode = VK_RETURN) and ((p.flags and (KF_ALTDOWN shr 8)) <> 0)
              and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then y:= 1
            else if (p.vkCode = VK_ESCAPE) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then y:= 1
            else if (p.vkCode = VK_ESCAPE) and ((GetKeyState(VK_MENU) and $8000) <> 0) then y:= 1
            else if (p.vkCode = 192) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then y:= 1
            else if (p.vkCode = VK_TAB) and ((GetKeyState(VK_MENU) and $8000) <> 0) then y:= 1;
          end;
        end;
        if y=1 then
        Result:=1 //如果为WIN功能键则屏蔽
        else
        Result:= CallNextHookEx(hHk, nCode, LWParam, LLParam); //其他键放下一个钩子
      end
    end;
    
    
    //卸载勾子
    UnHookWindowsHookEx(hHk);


  • 相关阅读:
    Vue模板
    一个人的旅行
    o2o家庭助手demo
    学习html5 app项目开发
    我最近的一段时间技术总结
    我最近的工作、生活状态
    swift学习初步(四)-- 函数
    swift学习初步(三)--控制流操作
    swift学习(二)--基本运算符、字符串、集合操作
    Swift学习初步(一)
  • 原文地址:https://www.cnblogs.com/whisht/p/4098861.html
Copyright © 2011-2022 走看看