0

在我的刽子手程序中,我试图使用一个数组来检测之前是否按下过一个字母,因此不能再次按下。

在我尝试这样做时,我尝试使用:

If targetarray[LastLetter] = 1 Then

'LastLetter' 是我的变量。

在我的代码的另一部分中,我也将数组存储为:

 Sub LetterArrays
  If GraphicsWindow.LastKey = "a" Then
    targetarray["a"] = 1
  ElseIf GraphicsWindow.LastKey = "b" Then
    targetarray["b"] = 1

等等...

初始代码检查字母 = 1 的 sub 位于按下字母 ( GraphicsWindow.KeyDown) 时调用的 sub 中,并且在我的 if 子句之前,我使用:targetarray[LastLetter] = 1作为将数组中的字母设置为 1 的方式。

如果这对您有意义并且您有解决方案,非常感谢您。

4

2 回答 2

0

据我了解,您不希望按两次相同的键。您可以这样做:

GraphicsWindow.KeyDown = KeyDown
i = 0

Sub KeyDown
    If Array.ContainsValue(keysPressed, GraphicsWindow.LastKey) Then
        ' key already pressed before
    Else
        ' key not pressed before
        i = i + i
        keysPressed[i] = GraphicsWindow.LastKey
        ' add code here
于 2021-06-19T21:48:38.770 回答
0

不是 100% 确定你在问什么,但如果你只是想检测按键,那么这段代码应该可以为你解决问题:

GraphicsWindow.KeyDown = KeyDown
GraphicsWindow.KeyUp = KeyUp

While 1 = 1
  Program.Delay(10)

  If Key["a"] Then
    TextWindow.WriteLine("Key 'a' was pressed")
  EndIf
EndWhile


Sub Keydown
  LastKeyDown = GraphicsWindow.LastKey
  Key[LastKeyDown] = "True"
EndSub

Sub KeyUp
  LastKeyUp = GraphicsWindow.LastKey
  Key[LastKeyUp] = "False"
EndSub
于 2018-12-10T17:09:42.947 回答