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

相关推荐

  • 小心onpropertychange在ie8上的地雷[通俗易懂]

    onpropertychangeonpropertychange的话,只要当前对象属性发生改变,都会触发事件,但是它是IE专属的

    2022年4月10日
  • artcam浮雕实例教程_artcam2018入门教程

    artcam浮雕实例教程_artcam2018入门教程记录过去,奋斗现在,展望未来(给未来即将结束的工作的’存档’)ArtCAM入门简单教程二、浮雕前言:这不是个很专业的浮雕设计教程,不过是很简单即可实现的入门教程,而更深入的浮雕学习建议查找更全面的网上教程或CAM浮雕书籍。   常用的矢量雕刻,详见:http://blog.sina.com.cn/s/blog_647ef76d0101jgwn.html开始之

    2022年9月5日
  • 公司测试环境k8s节点故障解决

    公司测试环境k8s节点故障解决

    2021年5月29日
  • ftp工具哪个好用_客户端游戏人气排行榜

    ftp工具哪个好用_客户端游戏人气排行榜序言:随着互联网的不断普及、发展,越来越多的人在使用FTP软件,它被广泛的应用于网页制作、网站更新、资源共享、数据传输等多个方面。“工欲善其事,必先利其器”,面对现在多如牛毛的各种FTP软件,我们到底选择哪一款才能更好的帮助我们呢?为此我们将针对当前比较流行的十款FTP客户端软件进行横向评测,通过下面的评测我们将会给出圆满的答案,希望能够给广大读者提供指引和帮助。导读:☆:

    2022年10月19日
  • ▲ Android 自定义可收缩的菜单

    ▲ Android 自定义可收缩的菜单

    2021年3月12日
  • Nginx + FastCGI架构部署指导

    Nginx + FastCGI架构部署指导本文主要介绍使用Nginx+FastCGI技术,搭建一个简单的WebServer的方法。关于Nignx的相关知识,请点击此处。关于FastCGI的相关知识,请点击此处。1.概述Nginx不能像Apache那样直接执行外部的可执行程序,但是Nginx可以作为代理服务器,将Web请求转发给后端(服务器中的)应用程序,这是Nginx的主要作用之一。在本文…

    2022年7月11日

发表回复

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

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