zoukankan      html  css  js  c++  java
  • 同时支持Directx input 和 Windows message的键盘模拟方法

    [转]http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/29cf2de9-412e-44dd-9050-174089d8e2a2/

    Simulating keyboard events:

    SendInput() is the function to use if DirectX applications need to receive the simulated keyboard events.  This function injects keyboard instructions at driver level - so these events will be received by both DirectX applications and those based on the window message queuing system.

    SendInput() supersedes keybd_event().  It's better to use SendInput() than keybd_event() because the former allows you to define an array of keyboard events (actually, a mixture of keyboard/mouse/other hardware inputs is possible) and then inject them all in the desired sequence with the guarantee that they won't be interspersed by either real hardware events or other simulated events.

    My application is a keyboard remapping application for games, so I had to be able to simulate keyboard events for DirectX games like most first-person shooters, as well as games that use the window queuing system such as Age of Empires.

    Intercepting and blocking events:

    Hooking allows keyboard messages going to windows to be intercepted and then modified or suppressed as desired.

    Using a keyboard hook, key presses can be detected system-wide regardless of whether the receiving application is DirectX-based or using message queuing.

    Does anyone know how if it's possible to suppress keyboard events being detected by a DirectX application?

    Update: note - DirectX applications may retrieve keyboard instructions before a Windows hook can receive notification, making them impossible to detect and then suppress.

    The following example simulates CTRL-C, which I used to obtain text from a control in another application (which was a custom listbox and didn't respond to the LB_GETTEXT message) by copying to the clipboard.

     

     

    Code Block

    INPUT inp[4];

    ZeroMemory(inp, sizeof(inp));

     

    //press the CONTROL key

    inp[0].type = INPUT_KEYBOARD;

    inp[0].ki.wVk = VK_CONTROL;

     

    //press the C key

    inp[1].type = INPUT_KEYBOARD;

    inp[1].ki.wVk = 'C';

     

    //release the C key

    inp[2] = inp[1];

    inp[2].ki.dwFlags |= KEYEVENTF_KEYUP;

    //release the CONTROL key

    inp[3] = inp[0];

    inp[3].ki.dwFlags |= KEYEVENTF_KEYUP;

    //simulate keyboard events and check success of function

    if (SendInput(4, inp, sizeof(INPUT)) != 4)

    //...then SendInput did not correctly insert 4 keyboard instructions

    //otherwise function was successful

  • 相关阅读:
    浅析嵌入式程序设计中的优化问题
    TCP粘包问题
    使用python 批量 配对t检验 医学 基础研究 数据分析
    Ubuntu误删系统文件修复办法
    飞思卡尔powerpc交叉编译环境的
    ubuntu packege下载网址
    数组对象里面对日期进行排序
    c# 字符串以逗号分割属性加上单引号
    Vue mysql 变量赋值, 获取数组
    Element vue Select 下拉框默认
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/3127934.html
Copyright © 2011-2022 走看看