钩子教程 – 原理(十六) : KeyboardProc

钩子教程 – 原理(十六) : KeyboardProc原文地址:http://www.zdexe.com/program/201004/590.html方法11:KeyboardProcFunctionThe KeyboardProc

大家好,又见面了,我是你们的朋友全栈君。

原文地址:http://www.zdexe.com/program/201004/590.html

方法11 : KeyboardProc Function

The KeyboardProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function whenever an application calls the GetMessage or PeekMessage function and there is a keyboard message (WM_KEYUP or WM_KEYDOWN) to be processed.

  KeyboardProc钩子子程是同SetWindowsHookEx方法一起使用的、用户定义的或者库定义的回调函数。无论什么时候,当应用程序调用GetMessage 或者PeekMessage方法时,系统都调用该方法,将有一个键盘消息(WM_KEYUP或者WM_KEYDOWN)被处理。

 

The HOOKPROC type defines a pointer to this callback function.KeyboardProc is a placeholder for the application-defined or library-defined function name.

  HOOKPROC类型定义了指向该回调函数的指针。KeyboardProc是程序定义的或者库定义的方法名字。

Syntax语法

LRESULT CALLBACK KeyboardProc(      
        int code,

    WPARAM wParam,

    LPARAM lParam

);

Parameters参数

code  : [in] Specifies a code the hook procedure uses to determine how to process the message. If code is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx. This parameter can be one of the following values.

  指定钩子子程使用的代码,来决定如何处理该消息。如果code小于0,钩子子程必须将该消息传递给CallNextHookEx方法,自己不进行任何进一步的处理,并且返回由CallNextHookEx方法返回的返回值。该参数可以是以下值之一:

  1.HC_ACTION :The wParam and lParam parameters contain information about a keystroke message. 

    参数 wParam 和 lParam 包含有键盘敲击消息的信息。

  2.HC_NOREMOVE :The wParam and lParam parameters contain information about a keystroke message, and the keystroke message has not been removed      from the message queue. (An application called thePeekMessage function, specifying the PM_NOREMOVE flag.)

    参数wParamlParam包含有键盘敲击消息的信息,键盘敲击消息还没有被从消息队列中移除。(应用程序调用PeekMessage方法,同时指定PM_NOREMOVE标志。)

wParam :[in] Specifies the virtual-key code of the key that generated the keystroke message. 

  指定生成键盘敲击消息的键的虚拟键码值。

lParam :[in] Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag. This parameter can be one or more of the following values.

  指定重复次数,扫描代码,扩展键标志,上下文代码,前期的键状态标志,转换状态标志。该参数可下列的一个或者多个值。

  0-15  : Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user’s holding down the key. 

    指定重复的次数。该值是,当用户持续按住一个键时,键盘敲击被重复的次数。

  16-23  :Specifies the scan code. The value depends on the OEM. 

    指定扫描代码。该值依赖于OEM。

  24  :Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the key is an       extended key; otherwise, it is 0. 

    指定该值是否是一个扩展键,例如功能键或者数字键盘上的键。如果是扩展键,该值为1,否则为0。

  25-28 : Reserved.

    保留

  29  :Specifies the context code. The value is 1 if the ALT key is down; otherwise, it is 0.

    指定上下文代码。如果ALT键被按下,该值为1,否则为0。

  30  : Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up. 

    指定前面的键状态。如果在消息发出之前该键被按下,值为1;如果键弹起,值为0。

  31  : Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released. 

    指定转换状态。如果键正在被按下,该值为0,如果正在被释放,则为1。

Return Value 返回值

If code is less than zero, the hook procedure must return the value returned by CallNextHookEx. If code is greater than or equal to zero, and the hook procedure did not process the message, it is highly recommended that you call CallNextHookEx and return the value it returns; otherwise, other applications that have installed WH_KEYBOARD hooks will not receive hook notifications and may behave incorrectly as a result. If the hook procedure processed the message, it may return a nonzero value to prevent the system from passing the message to the rest of the hook chain or the target window procedure.

  如果code小于0,钩子子程必须返回由CallNextHookEx返回的返回值。如果code大于等于0,表示钩子子程没有处理该消息,强烈要求调用CallNextHookEx方法,并返回由它返回的返回值;否则,其它已经安装有WH_KEYBOARD钩子的应用程序将收不到钩子通知,可能导致行为的错误。如果钩子子程处理了该消息,可能返回一个非0值,用来阻止系统将该消息传递给钩子链表中的其它钩子或者目的窗体程序。

Remarks 备注

An application installs the hook procedure by specifying theWH_KEYBOARD hook type and a pointer to the hook procedure in a call to the SetWindowsHookEx function.

  应用程序通过下面的方法安装该钩子子程: 指定WH_KEYBOARD钩子类型;指定在调用SetWindowsHookEx的方法中的一个指向钩子子程的指针。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/155273.html原文链接:https://javaforall.net

(0)
上一篇 2022年7月2日 下午1:46
下一篇 2022年7月2日 下午1:46


相关推荐

  • python字典dict方法_python中dict的用法

    python字典dict方法_python中dict的用法文章目录:一.字典(dict)的概念:二.字典(dict)的定义:1.一般格式:2.空字典:3.举例:注意:三.字典(dict)的一些基本操作:1.增:2.删:3.查:4.改:四.字典(dict)的常见操作:五.字典三种取值方式:1.value=字典名[key]:2.setdefault:3.get:六.字典的遍历:1.key:2.value:3.item:4.依次打印key和value:5.元素值和对应的下标索引(enumerate()):一.字典(dict)的概念:Python字典是另一种可变容器模

    2022年10月6日
    3
  • springboot的启动流程图_@SpringBootApplication

    springboot的启动流程图_@SpringBootApplication首先会new一个SpringApplication然后在构造方法里初始化一些属性。判断应用类型是响应式REACTIVE的还是Web应用SERVLET去spring.factories文件加载初始化器ApplicationContextInitializer去spring.factories文件加载监听器ApplicationListener实例化之后执行run方法主体,run执行流程是基于观察者模式的,整个SpringBoot的启动流程就是各种事件的发布。获取并启用监听器Applicati..

    2025年9月5日
    4
  • IDEA 注释模板

    IDEA 注释模板IDEA 注释模板

    2026年3月19日
    3
  • CAP定理整理_craig定理

    CAP定理整理_craig定理CAP定理是分布式系统设计中最基础、最关键的理论,CAP定理又称CAP原则,指的是在一个分布式系统中,Consistency(一致性)、Availability(可用性)、Partitiontolerance(分区容错性),最多只能同时三个特性中的两个,三者不可兼得CAP的定义Consistency(一致性):“allnodesseethesamedataatthe…

    2025年6月23日
    6
  • Cursor 项目级提示词规范:把需求写成 AI 可执行任务单

    Cursor 项目级提示词规范:把需求写成 AI 可执行任务单

    2026年3月16日
    3
  • StringBuilder 使用方法

    StringBuilder 使用方法String 字符串常量 StringBuffer 字符串变量 线程安全 StringBuilde 字符串变量 非线程安全 nbsp 简要的说 String 类型和 StringBuffer 类型的主要性能区别其实在于 String 是不可变的对象 因此在每次对 String 类型进行改变的时候其实都等同于生成了一个新的 String 对象 然后将指针指向新的 String 对象 所以经常

    2026年3月26日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号