我需要在以下代码中使用配置文件中定义的键:
switch (e.KeyCode)
{
case Keys.D1:
if (keyIsDown[Keys.D1]) return;
if (beatload1.Text == "Waiting 01.wav")
{
MessageBox.Show("No beat loaded.");
return;
}
try
{
keyIsDown[Keys.D1] = true;
Beat1.Image = Beatpadpc.Properties.Resources.white_square_button;
Bass.BASS_ChannelGetInfo(stream1, info);
if (b_toggler1 == "0")
{
if (!String.Equals(info.filename, path1))
{
Bass.BASS_StreamFree(stream1);
stream1 = Foo.GetStream1(path1);
}
Bass.BASS_ChannelSetAttribute(stream1, BASSAttribute.BASS_ATTRIB_VOL, vol);
Bass.BASS_ChannelPlay(stream1, true);
}
else if (b_toggler1 == "1")
{
if (!String.Equals(info.filename, path37))
{
Bass.BASS_StreamFree(stream1);
stream1 = Foo.GetStream1(path37);
}
Bass.BASS_ChannelSetAttribute(stream1, BASSAttribute.BASS_ATTRIB_VOL, vol);
Bass.BASS_ChannelPlay(stream1, true);
}
}
catch (FileNotFoundException)
{
MessageBox.Show("File has been moved." + "\n" + "Please relocate it now!");
}
break;
case Keys.D2:
if (keyIsDown[Keys.D2]) return;
if (beatload2.Text == "Waiting 02.wav")
{
MessageBox.Show("No beat loaded.");
return;
}
try
{
keyIsDown[Keys.D2] = true;
Beat2.Image = Beatpadpc.Properties.Resources.white_square_button;
Bass.BASS_ChannelGetInfo(stream2, info);
if (b_toggler1 == "0")
{
if (!String.Equals(info.filename, path2))
{
Bass.BASS_StreamFree(stream2);
stream2 = Foo.GetStream2(path2);
}
Bass.BASS_ChannelSetAttribute(stream2, BASSAttribute.BASS_ATTRIB_VOL, vol);
Bass.BASS_ChannelPlay(stream2, true);
}
if (b_toggler1 == "1")
{
if (!String.Equals(info.filename, path38))
{
Bass.BASS_StreamFree(stream2);
stream2 = Foo.GetStream2(path38);
}
Bass.BASS_ChannelSetAttribute(stream2, BASSAttribute.BASS_ATTRIB_VOL, vol);
Bass.BASS_ChannelPlay(stream2, true);
}
}
catch (FileNotFoundException)
{
MessageBox.Show("File has been moved." + "\n" + "Please relocate it now!");
}
break;
}
包含应使用的键的配置文件如下所示:
<add key="x36_key1" value="D1"/>
<add key="x36_key2" value="D2"/>
因此,不是在代码中手动定义密钥,而是如何进行,以便在配置文件中定义呢?