WPF - Send Keys Redux

我的未来我决定 提交于 2019-12-04 01:49:25

I've created a little library that might probably help you out with mocking the Shift key:

http://wpfsendkeys.codeplex.com/

http://blogs.msdn.com/b/kirillosenkov/archive/2010/07/09/wpf-sendkeys-or-mocking-the-keyboard-in-wpf.aspx

try this

System.Windows.Forms.SendKeys.SendWait("{Tab}");

In WPF Application, SendKeys.Send not working, But SendWait is working fine.

Dunc

Create a MockKeyboardDevice like this (kudos to Jared Parsons):

https://github.com/jaredpar/VsVim/blob/master/Test/VimCoreTest/Mock/MockKeyboardDevice.cs

Usage:

var modKey = ModifierKeys.Shift;
var device = new MockKeyboardDevice(InputManager.Current)
    {
        ModifierKeysImpl = modKey
    };
var keyEventArgs = device.CreateKeyEventArgs(Key.Tab, modKey);
...

A usage example:

https://github.com/jaredpar/VsVim/blob/master/Test/VimWpfTest/VimKeyProcessorTest.cs

REA_ANDREW

I simulate what you say fine using the following is this not what you mean?

public Window1()
{
    InitializeComponent();


    Loaded += new RoutedEventHandler(Window1_Loaded);
}

void Window1_Loaded(object sender, RoutedEventArgs e)
{
    WebBrowser1_PreviewKeyDown(this, new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 1, Key.LeftShift));
    WebBrowser1_PreviewKeyDown(this, new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 1, Key.Tab));
}

private void WebBrowser1_PreviewKeyDown(object sender, KeyEventArgs e)
{
    System.Diagnostics.Debug.WriteLine(e.Key);
}

OUTPUT:

LeftShift
Tab
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!