Supports keyboard simulation of DirectX input and Windows message.

Source: Internet
Author: User

[Transfer] 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 encoded ed 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 processing 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 indium [4];

Zeromemory (indium, Sizeof(Indium ));

 

// Press the control key

Indium [0]. type = input_keyboard;

Indium [0]. Ki. wvk = vk_control;

 

// Press the C key

Indium [1]. type = input_keyboard;

Indium [1]. Ki. wvk = 'C';

 

// Release the C key

Indium [2] = indium [1];

Indium [2]. Ki. dwflags | = keyeventf_keyup;

// Release the control key

Indium [3] = indium [0];

Indium [3]. Ki. dwflags | = keyeventf_keyup;

// Simulate Keyboard Events and check success of Function

If (Sendinput (4, indium, Sizeof(Input ))! = 4)

//... Then sendinput did not correctly insert 4 keyboard instructions

// Otherwise function was successful

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.