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

  • 相关阅读:
    MySQL 中 where id in (1,2,3,4,...) 的效率问题讨论
    创建,增加,删除mysql表分区
    mysql分区及实例演示
    MySQL的表分区详解
    MySQL 存储过程传参之in, out, inout 参数用法
    MySQL里面的子查询实例
    超详细mysql left join,right join,inner join用法分析
    MySQL force Index 强制索引概述
    MyISAM和InnoDB的索引在实现上的不同
    java中的守护线程
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/3127934.html
Copyright © 2011-2022 走看看