钩子教程 – 原理(十六) : 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.)

    参数wParam和lParam包含有键盘敲击消息的信息,键盘敲击消息还没有被从消息队列中移除。(应用程序调用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)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • Linux 最常用命令整理,建议收藏!

    Linux 最常用命令整理,建议收藏!

    2022年2月17日
  • docker 删除_Docker删除镜像和容器[通俗易懂]

    docker 删除_Docker删除镜像和容器[通俗易懂]当一个host中镜像和容器较多,需要重置时可选择删除其中部分或全部的镜像和容器。那么你就需要下面的操作了。1、删除容器1)首先需要停止所有的容器dockerstop$(dockerps-a-q)2)删除所有的容器(只删除单个时把后面的变量改为containerid即可)dockerrm$(dockerps-a-q)2、删除镜像1)查看host中的镜像dockeri…

    2022年4月19日
  • 理解G1收集器

    理解G1收集器G1这个名字是怎么来的collecttheregionswiththeleastlivedatafirst(GarbageFirst).G1适合什么情景多核多CPU而且大内存大内存要求低停顿G1如何实现-XX:MaxGCPauseMillis所设置的目标?首先这个目标是个软指标。对于新生代来说,过G1自动调整新生代的大小。对于老年代来说,每次MixedG…

    2022年5月18日
  • python 拼接字符串字作为字符串使用(python连接字符串)

    Python字符串拼接数字的方法发布时间:2020-08-0515:40:44来源:亿速云阅读:99作者:小新这篇文章将为大家详细讲解有关Python字符串拼接数字的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。Python字符串拼接数字在某些特殊场景中,我们需要将字符串与数字进行拼接,而Python不允许直接拼接数字和字符串,程序必须先将数字转换成字…

    2022年4月12日
  • I/O接口_overlapping

    I/O接口_overlappingOverlappedI/O是Windows系统上的AsynchronousI/Oimplementation。啥叫asynchronousI/O?借用LinuxManpage中对AIO的

    2022年8月5日
  • BIST

    BISTBIST即是在设计时在电路中植入相关功能电路用于提供自我测试功能的技术,BIST把测试仪的部分功能转移到电路内部,用嵌入到电路中的测试电路提供输入测试向量和分析响应的功能,最后输出简单的测试结果。根据被测试的对象不同,BIST测试分为LogicBIST和MemoryBIST。LogicBIST原理结构:实现方法一般基于STUMPS结构,包含测试向量生成模块PRPG、响应分析模块M

    2022年10月22日

发表回复

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

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