0
UWPアプリでKeyupやkeydownのようなキーボードイベントをシミュレートする方法。私は自分のキーボードを作りましたが、キーボードイベントをそれ。 私はuwpで何も見つからなかったし、SendKeys.Send()メソッドもUWPでは利用できません。UWPアプリでKeyupやkeydownのようなキーボードイベントをシミュレートする
UWPアプリでKeyupやkeydownのようなキーボードイベントをシミュレートする方法。私は自分のキーボードを作りましたが、キーボードイベントをそれ。 私はuwpで何も見つからなかったし、SendKeys.Send()メソッドもUWPでは利用できません。UWPアプリでKeyupやkeydownのようなキーボードイベントをシミュレートする
私は自分のキーボードを作ったのではなく、キーボードイベントを追加したいと思っています。私はuwpで何の方法も見つけられず、SendKeys.Send()メソッドもUWPでは利用できません。あなたの条件のために
、あなたはキーボードKeyDown
をシミュレートするカスタムイベントハンドラー、カスタムユーザーコントロールでKeyUp
イベントを作成することができます。重要なポイントは、カスタムイベントハンドラを呼び出すタイミングです。私は参照を持つことができるシンプルなサンプルを作成しています。
CustomKeyBoard.xaml
<UserControl
x:Class="UIKeyBoardTest.CustomKeyBoard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UIKeyBoardTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:control ="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<GridView VerticalAlignment="Center" HorizontalAlignment="Center" ItemClick="GridView_ItemClick" IsItemClickEnabled="True">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid MaximumRowsOrColumns="3" Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Background="White"
BorderBrush="Black"
BorderThickness="1">
<TextBlock Text="{Binding }" HorizontalAlignment="Center" TextAlignment="Center" VerticalAlignment="Center" FontSize="40" Width="55" />
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
<x:String>1</x:String>
<x:String>2</x:String>
<x:String>3</x:String>
<x:String>4</x:String>
<x:String>5</x:String>
<x:String>6</x:String>
<x:String>7</x:String>
<x:String>8</x:String>
<x:String>9</x:String>
</GridView>
</Grid>
</UserControl>
CustomKeyBoard.xaml.cs
public sealed partial class CustomKeyBoard : UserControl
{
public delegate void BoilerLogHandler(string value);
public event BoilerLogHandler BoilerEventLog;
public CustomKeyBoard()
{
this.InitializeComponent();
}
private void GridView_ItemClick(object sender, ItemClickEventArgs e)
{
if (BoilerEventLog != null)
{
BoilerEventLog(e.ClickedItem.ToString());
}
}
}
使用
<TextBox x:Name="box" PlaceholderText="Please input something" Margin="0,50,0,60" />
<local:CustomKeyBoard
HorizontalAlignment="Center"
VerticalAlignment="Center"
BoilerEventLog="CustomKeyBoard_BoilerEventLog" />
private void CustomKeyBoard_BoilerEventLog(string value)
{
box.Text = value;
}
「自分のキーボードを作った」とはどういう意味ですか? –
私は、簡単なキーボードをプログラムでアルファベットと数字で作成したと言っています。 – user3309634
次に、そのコントロールからのイベントを使用してみませんか?質問にコードを添付してください –