我第一次使用通用Windows应用程序并希望在某些事件中从配置文本文件中保存和加载Virtualkeys。我已经设置了写作部分但我仍然坚持如何将“密钥字符串”从文本文件转换为Virtualkey。
一些缩短的代码,以便更好地理解:
private IDictionary<GamepadButtons, VirtualKey> assignedButtons = new Dictionary<GamepadButtons, VirtualKey>();
// Read keys from dic
private void GetKeys()
{
if (assignedButtons.ContainsKey(GamepadButtons.Aux1)) { aux1_str = (assignedButtons[GamepadButtons.Aux1]).ToString(); } else if (!assignedButtons.ContainsKey(GamepadButtons.Aux1)) { aux1_str = "0"; }
}
// Write config file
async private void WriteConfig()
{
appfolder = ApplicationData.Current.LocalFolder;
try
{
config = await appfolder.CreateFileAsync("config.ini", CreationCollisionOption.ReplaceExisting);
var writer = await config.OpenStreamForWriteAsync();
string[] paddles = { aux1_str };
using (StreamWriter ConfigWriter = new StreamWriter(writer)) { foreach (string line in paddles) ConfigWriter.WriteLine(line); }
}
catch { };
}
// Read config text file
async private void GetConfig()
{
appfolder = ApplicationData.Current.LocalFolder;
try
{
config = await appfolder.GetFileAsync("config.ini");
var reader = await config.OpenStreamForReadAsync();
StreamReader ConfigReader = new StreamReader(reader);
aux1_str = ConfigReader.ReadLine();
}
catch { };
}
// Assign keys
private void PushKeys()
{
assignedButtons[GamepadButtons.Aux1] = ???
}
现在,如果我可以访问System.Windows.Forms或者如果我可以使用MapVirtualKey,那么我可能知道我的方法,但是UWP都不是。
任何想法如何解决这个问题?也许有更好的方法将Virtualkey存储到文本文件(数字)?再次,由于应用程序是UWP,我有点卡住了。
谢谢和最诚挚的问候!