程序没有捕获密钥
本文关键字:密钥 程序 | 更新日期: 2023-09-27 17:49:17
正如标题所说,我的程序有问题。我创造了一个功能(游戏邦注:一个战斗功能,玩家可以在textbox
中编写并按下按钮)。战斗结束后,我的程序没有捕获按下的键,除非我在程序中再次使用alt-tab和alt-tab。我该怎么做?
//capture key function
private void joc_KeyDown_1(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F4 && e.Alt && permite_pasi == true)
{
enableClose = false;
}
if (e.KeyCode == Keys.D || e.KeyCode == Keys.Right && permite_pasi == true)
{
step(6); //step() is the movement function
}
if (e.KeyCode == Keys.W || e.KeyCode == Keys.Up && permite_pasi == true)
{
step(8);
}
if (e.KeyCode == Keys.A || e.KeyCode == Keys.Left && permite_pasi == true)
{
step(4);
}
if (e.KeyCode == Keys.S || e.KeyCode == Keys.Down && permite_pasi == true)
{
step(2);
}
}
//movement function
public void step(int directie)
{
if (directie == 6 && checkstep(directie) == true) { //checkstep() is a function which check the environment for obstacles
if (check_NPC(jucator.x, jucator.y) > 0) // function for checking the environment
{
scorenpc = check_NPC(jucator.x, jucator.y); //some variabile
NPC(check_NPC(jucator.x, jucator.y), jucator.score); // the battle function
}
else
{
//movement instructions
}
}
if (directie == 4 && checkstep(directie) == true)
{
if (check_NPC(jucator.x, jucator.y) != 0)
{
scorenpc = check_NPC(jucator.x, jucator.y);
NPC(check_NPC(jucator.x, jucator.y), jucator.score);
}
else
{
//movement instructions
}
}
if (directie == 8 && checkstep(directie) == true)
{
if (check_NPC(jucator.x, jucator.y) > 0)
{
scorenpc = check_NPC(jucator.x, jucator.y);
NPC(check_NPC(jucator.x, jucator.y), jucator.score);
}
else
{
//movement instructions
}
}
if (directie == 2 && checkstep(directie) == true)
{
if (check_NPC(jucator.x, jucator.y) != 0)
{
scorenpc = check_NPC(jucator.x, jucator.y);
NPC(check_NPC(jucator.x, jucator.y), jucator.score);
}
else
{
//movement instructions
}
}
}
如果有必要的话,我将把剩下的代码放在下次编辑中。
在战斗函数结束时,我使用this.Focus()
。