zoukankan      html  css  js  c++  java
  • keybd_event函数用法

    转自不用winio,直接达到驱动级模拟键盘效果的keybd_event函数用法


    键盘模拟技术是在编写游戏外挂时经常使用的技术。但是由于很多游戏采用了directinput的方式,使得发送的一般键盘消息无法被程序收到。这时候需要使用驱动级的键盘模拟技术,直接发送键盘的硬件扫描码,达到模拟键盘的目的。

        目前网络上流行的做法是使用winio模拟键盘硬件扫描码,但是winio并不稳定,时常有严重错误发生。这里电王介绍一种稳定方便的方式——使用keybd_event函数,这种方法非常简单,而且极为稳定。

        参阅MSDN,我们可以发现以下介绍:

    VOID keybd_event(
      BYTE bVk,           // virtual-key code
      BYTE bScan,         // hardware scan code
      DWORD dwFlags,      // flags specifying various function options
      DWORD dwExtraInfo   // additional data associated with keystroke
    );

    Parameters

    bVk
    Specifies a virtual-key code. The code must be a value in the range 1 to 254.
    bScan
    Specifies a hardware scan code for the key.
    dwFlags
    A set of flag bits that specify various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags.
    Value Meaning
    KEYEVENTF_EXTENDEDKEY If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).
    KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is being depressed.

    dwExtraInfo
    Specifies an additional 32-bit value associated with the key stroke.
     

        其中第二个参数 BYTE bScan 其实就是键盘的硬件扫描码。很多资料上都简单的把这个参数设为0,而使用第一个参数设置键盘的虚拟值,浪费了这个函数的功能。在使用这个函数时,只要把一参的虚拟值和二参的扫描码值设为对应的一个按键(注意,如果只设置一参而把二参设为0,很多使用directinput的游戏是不能响应的),就可令目前几乎所有游戏成功响应。


  • 相关阅读:
    linux环境下的makefile文件的编写(zz)
    linux 中vim的退格键的使用问题
    Design Complier Synthesis Script Templet
    Synthesis Summary 逻辑综合总结
    .net加密
    timestamp (TransactSQL) 时间戳
    ADO.NET连接池
    ASP.NET Web数据控件
    高效的读取二进制数据
    GridView
  • 原文地址:https://www.cnblogs.com/noble/p/4144127.html
Copyright © 2011-2022 走看看