gpt4 book ai didi

c# - UWP 中的键盘快捷键

转载 作者:行者123 更新时间:2023-12-03 23:16:37 24 4
gpt4 key购买 nike

我在用户控件中定义了一个 KeyDown 事件。目前,当您按 Enter 时它可以工作。我希望它也处理 ctrl + v 组合键,以便粘贴复制的文本并执行一些操作。
说明:我的 KeyDown 事件处理程序接收到一个按下的键,如果是 Enter,则获取此控件中的当前焦点(例如,焦点在某个 textBox 上),检查 TextBox "X"中是否有任何数据,如果有,另一个 TextBox 是自动完成的。我需要在文本框“X”中插入文本时,自动完成文本框的其余部分。如何强制程序并执行插入并执行我的自动完成代码?

private async void OnKeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key != VirtualKey.Enter) return;

var focusedElement = FocusManager.GetFocusedElement();

if (focusedElement == LocationName || focusedElement == AddressTextBox ||
focusedElement == Latitude || focusedElement == Longitude)
{
e.Handled = true;
}

if (IsAddressTextValid)
{
var mapLocation = await FindFirstMapLocationAsync(AddressTextBox.Text);

if (mapLocation != null)
{
LatitudeText = mapLocation.Point.Position.Latitude.ToString();
LongitudeText = mapLocation.Point.Position.Longitude.ToString();
}
}
}

最佳答案

要处理 Ctrl+V,实际上 Justin 有一个 post这可以帮助。

 Window.Current.CoreWindow.KeyDown += (s, e) =>
{
var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control);
if (ctrl.HasFlag(CoreVirtualKeyStates.Down) && e.VirtualKey == VirtualKey.V)
{
// do your stuff
Debug.WriteLine("ctrl+V has been triggered");
}
if(e.VirtualKey==VirtualKey.Enter)
{
Debug.WriteLine("Enter triggered");
}

};

但是对于如何强制更新其他文本框,对您的逻辑不太确定。更改文本对您不起作用?

关于c# - UWP 中的键盘快捷键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49697587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com