钩子教程 – 原理(十六) : 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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • git生成ssh key命令(keystore文件)

    https://blog.csdn.net/yxl7808a/article/details/53139186https://blog.csdn.net/frank_wu/article/details/53615165由以上俩个方案总结而来1.创建cordova项目;2.我们需要先生成一个数字签名文件(keystore)。这个文件只需要生成一次。以后每次si…

    2022年4月15日
    90
  • 4个基本不等式的公式高中_基本不等式公式四个[通俗易懂]

    4个基本不等式的公式高中_基本不等式公式四个[通俗易懂]课题:基本不等式第2课时时间:2010.10.29地点:阳春四中年级:高二【教学目标】1.知识与技能:进一步掌握基本不等式;会应用此不等式求某些函数的最值;能够解决一些简单的实际问题2.过程与方法:通过两个例题的研究,进一步掌握基本不等式,并会用此定理求某些函数的最大、…均值不等式【使用说明】1.自学课本P69—P71,仔细阅读课本,课前完成预习学案,牢记基础知识,掌握基本…

    2022年4月28日
    97
  • Python图像处理之小波去噪

    Python图像处理之小波去噪在此前的文章中,我们讨论了在Python中利用pywt包提供的API对图像做小波分解的基本方法。小波变换在图像处理中的一个具体应用就是平滑去噪。后续我们还会从原理上讨论如何利用小波变换来设计图像去噪算法。但在此之前,本文将主要演示,利用Python中已有的API进行图像小波去噪的方法及效果

    2022年6月26日
    119
  • python开两个守护线程_hdfs守护线程

    python开两个守护线程_hdfs守护线程**守护线程**是区别于用户线程哈,**用户线程**即我们手动创建的线程,而守护线程是程序运行的时候在后台提供一种**通用服务的线程**。垃圾回收线程就是典型的守护线程。

    2022年10月15日
    6
  • charles导致mac无法上网_charles手机设置代理后上不了网

    charles导致mac无法上网_charles手机设置代理后上不了网前言charles关闭后,发现网页突然打开了,那大概率是设置了代理,但明明已经关闭了charles,这是由于mac网络偏好设置中,使用的是手动代理,将其改为自动即可解决方法1打开网络偏好设置,

    2022年7月30日
    113
  • ExtJs自学教程(1):一切从API開始

    ExtJs自学教程(1):一切从API開始

    2021年12月10日
    33

发表回复

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

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