WPFwiki, wpf, wiki, .net 3.0, windows presentation foundation, FAQ, free resources, solution, development, microsoft Home of the world's largest WPF FAQ
Edit

Category

Input

Edit

Question

How can I simulate basic keyboard events?

Edit

Answer

In order to simulate basic keyboard events, you simply need to build a KeyEventArgs object with the appropriate parameters and send it either directly to the element on which you wish to simulate the input or access the InputManager if the input needs to be simulated on the normal input recipient.

To build the KeyEventArgs, you need to specify the following at construction:

1. The KeyboardDevice that should be "simulated": If there is no specific device you wish to simulate, simply pass Keyboard.PrimaryDevice.

2. A PresentationSource object: You can obtain a valid PresentationSource by getting the KeyboardDevice.ActiveSource property.

3. A timestamp (can be 0).

4. The Key for which the input is simulated.

Once the KeyEventArgs object is constructed, you need to set the RoutedEvent member of the object to the input you wish to simulate. wpfwiki Air Jordan. For example:

KeyEventArgs e = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 
                                  0, Key.Enter);
e.RoutedEvent = Keyboard.KeyDownEvent;


You can then sent the input simulation either by:

targetElement.RaiseEvent(e);


or

InputManager.Current.ProcessInput(e);


This will simulate the Enter key "Down" input for the "targetElement" object or for the currently focused element.

The types of input that can be simulated are as follows:

PreviewKeyDownEvent, KeyDownEvent, PreviewKeyUpEvent, KeyUpEvent.

Note that this method will not simulate text input but only keystrokes.

For the simulation of text input, refer to related links.

Edit

Related Links

Input: Simulating text input C++ Help men's dress shirts outdoor lighting pellet stoves reverse phone lookup outdoor security lighting used pellet stoves outdoor flood lights discount pellet stoves matelasse custom essays DWI Attorney Albanylace wig philippine travel travel asia weber natural gas grill weber natural gas grill Weber Natural Gas Grill Pacquiao Vs Marquez mayweather vs ortiz home ideas mayweather vs ortiz live streaming pacquiao vs marquez st-pierre vs diaz Fifa World Cup hopkins vs dawson pacquiao vs marquez tickets donaire vs narvaez cotto vs margarito donaire vs narvaez tickets cotto vs margarito live streaming st-pierre vs diaz tickets pacquiao vs marquez

=

============================================= http://therothirarules.com/rules-of-roth-ira roth ira rules http://bestdrivingschools.org/truck-driving-school.htm Truck Driving School http://theculinaryartsschools.org/ culinary arts http://bestseoservicescompany.com/ Link building services

=

=================================================



All content is Copyright ©2007 Xceed Software Inc. unless otherwise indicated. See the Terms of Service. Contributors must read and agree to the Contribution Policy. WPFwiki is brought to you by Xceed, makers of the powerful yet free Xceed DataGrid for WPF.