WPF - 发送键终极版 [英] WPF - Send Keys Redux

查看:319
本文介绍了WPF - 发送键终极版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我使用的是第三部分的WPF网格控件是硬编码为只接受某些键进行快捷的反应和其中之一是Shift-Tab键。
然而,我的用户群是用来打向上和向下箭头,并告诉他们'不'是不是现在的选项。所以,我唯一的,我认为选择是向下截取预览键和发送不同的击键组合。

So, I'm using a third-part wpf grid control that is hard-coded to only accept certain keystrokes to perform short-cut reactions and one of those is Shift-Tab. However, my user-base is used to hitting up arrow and down arrow and telling them 'no' isn't an option right now. So my only option I think is to intercept the preview key down and send a different key stroke combination.

现在,我使用下面的代码,我发现在这里

Now, I am using the following code that I found on here to send a Tab when the user presses the Down arrow:

if (e.Key == Key.Down)
{
    e.Handled = true;
    KeyEventArgs eInsertBack = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.Tab);
    eInsertBack.RoutedEvent = UIElement.KeyDownEvent;
    InputManager.Current.ProcessInput(eInsertBack);
}



然而,该方法是有限的,因为你似乎不能够模拟SHIFT键的新闻? WPF似乎看Keyboard.Modifiers要能读一个Shift或Ctrl键,但似乎没有任何设施,以编程方式设置Keyboard.Modifiers。 ?任何帮助那里

However, this method is limited in that you don't seem to be able to simulate a press of the Shift Button? WPF seems to look at the Keyboard.Modifiers to be able to 'read' a Shift or Ctrl, but there doesn't seem to be any facility to Set the Keyboard.Modifiers programatically. Any help out there?

推荐答案

我创建了一个小图书馆这可能会帮助您与嘲讽Shift键:

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-在wpf.aspx

这篇关于WPF - 发送键终极版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆