01-15-2025, 05:05 PM
Please try the subroutine method which sets key and Lastkey before the loop, you don't appear to be doing this.
This works every time for me, so I feel there may be something else going on in your program and would like to understand that first. There are other ways also to just wait for a Return key press as I suggested so don't want to add a 'weird hack' feature to change something that I think may be covering up some other issue and could get you or others into other problems.
Can you share an actual (simplified if possible) program that shows the issue I can reproduce, using the WaitForReturnKey subroutine below.
Another way to do it:
And another:
This works every time for me, so I feel there may be something else going on in your program and would like to understand that first. There are other ways also to just wait for a Return key press as I suggested so don't want to add a 'weird hack' feature to change something that I think may be covering up some other issue and could get you or others into other problems.
Can you share an actual (simplified if possible) program that shows the issue I can reproduce, using the WaitForReturnKey subroutine below.
Code:
GraphicsWindow.Show()
While ("True")
WaitForReturnKey()
GraphicsWindow.BackgroundColor = GraphicsWindow.GetRandomColor()
EndWhile
Sub WaitForReturnKey
key = "" 'Make sure key isn't initially Return before LastKey sets it
LDTextWindow.SendKey(GraphicsWindow.Title,"Space") 'Send a Space key so initially LastKey is not Return
Program.Delay(10)
While key <> "Return"
key = GraphicsWindow.Lastkey
Program.Delay(10) 'Don't mash cpu
EndWhile
EndSub
Another way to do it:
Code:
GraphicsWindow.Show()
GraphicsWindow.KeyDown = OnKeyDown
While ("True")
WaitForReturnKey()
GraphicsWindow.BackgroundColor = GraphicsWindow.GetRandomColor()
EndWhile
Sub WaitForReturnKey
key = ""
While (key <> "Return")
Program.Delay(10)
EndWhile
EndSub
Sub OnKeyDown
key = GraphicsWindow.LastKey
EndSub
And another:
Code:
GraphicsWindow.Show()
While ("True")
WaitForReturnKey()
GraphicsWindow.BackgroundColor = GraphicsWindow.GetRandomColor()
EndWhile
Sub WaitForReturnKey
While (LDUtilities.KeyDown("Return") <> "True")
Program.Delay(10)
EndWhile
EndSub