inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_1);替换“VK_1”使用“VK_”button.content [英] inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_1); Replace "VK_1" with "VK_"button.content
问题描述
        是否可以替换 VK_1  有这样的东西VK_(发件人为按钮)。内容
Is it possible to replace VK_1 with something like this VK_(sender as Button).Content
来自此
from this
private void btnSendContent_Click(object sender,RoutedEventArgs e)
{            
inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_1);
}
private void btnSendContent_Click(object sender, RoutedEventArgs e)
{
inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_1);
}
到这个
to this
private void btnSendContent_Click(object sender,RoutedEventArgs e)
{        
inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_(发件人为Button)。内容;);
}
private void btnSendContent_Click(object sender, RoutedEventArgs e)
{
inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_(sender as Button).Content;);
}
推荐答案
可以这样做:
inputSimulator.Keyboard.KeyDown((VirualKeyKode)((Button)sender).Tag);
inputSimulator.Keyboard.KeyDown((VirualKeyKode)((Button)sender).Tag);
您必须在初始化阶段准备按钮的标记属性,例如:
You must prepare the Tag property of your buttons on initialisation stage, for example:
<跨度>&NBSP;&NBSP; myButton1.Tag = VirtualKeyCode.VK_1;
myButton1.Tag = VirtualKeyCode.VK_1;
可能内容也可以用。如果是类似"VK_1"的字符串,请参阅
Enum.Parse 。
Probably Content can be used too. If it is a string like "VK_1", then see Enum.Parse.
这篇关于inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_1);替换“VK_1”使用“VK_”button.content的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!