Without going into unnecessary detail, I am developing a reasonably involved GUI application. I noticed a very peculiar difference in behaviour from one computer to another. The original code is large but I have managed to write this little one which shows the issue clearly with dummy calculations.
Basically, when the user takes the "Start loop" option, a long calculation is set in motion which the user may interrupt with ESC. A Flushkeys is executed upon entry to the function in case more than one ESC or anything else has been keyed previously.
The funny thing is that it works perfectly on my computer at home, but on my computer at work Flushkeys doesn't appear to clear anything. i.e. if 3 ESCs have been pressed, 3 clicks on "Start loop" become necessary to perform the function without exiting. If x ESCs are pressed, x clicks on "Start loop" are needed.
So for the same code, one computer executes Flushkeys correctly and one doesn't. In every other way their function is identical.
What have I missed here ? I cannot imagine why this should be so.
;Make a simple window
window=CreateWindow("",50,50,200,200,0,7)
menu=WindowMenu(window)
menu1=CreateMenu("Test",1,menu)
menu1_1=CreateMenu("Start loop",11,menu1)
UpdateWindowMenu window
Global workarea=CreateCanvas(0,0,200,200,window)
SetBuffer CanvasBuffer(workarea)
ClsColor 0,0,0
Cls
Color 255,255,255
;Event loop - only two will do for the purpose of this example
While WaitEvent()
Select EventID()
Case $803
End
Case $1001
If EventData()=11 Then doloop()
End Select
Wend
;Slow operation involving lots of calculation
;but interruptible by ESC
Function doloop()
FlushKeys
For i=0 To 100000
;Show that the operation is actually doing something
If (i Mod 1000)=0 Then
Cls
Text 20,20,Str(i)
FlipCanvas workarea
EndIf
For j=0 To 100000
k=i*j
Next
If GetKey()=27 Then Exit
Next
End Function
Basically, when the user takes the "Start loop" option, a long calculation is set in motion which the user may interrupt with ESC. A Flushkeys is executed upon entry to the function in case more than one ESC or anything else has been keyed previously.
The funny thing is that it works perfectly on my computer at home, but on my computer at work Flushkeys doesn't appear to clear anything. i.e. if 3 ESCs have been pressed, 3 clicks on "Start loop" become necessary to perform the function without exiting. If x ESCs are pressed, x clicks on "Start loop" are needed.
So for the same code, one computer executes Flushkeys correctly and one doesn't. In every other way their function is identical.
What have I missed here ? I cannot imagine why this should be so.
;Make a simple window
window=CreateWindow("",50,50,200,200,0,7)
menu=WindowMenu(window)
menu1=CreateMenu("Test",1,menu)
menu1_1=CreateMenu("Start loop",11,menu1)
UpdateWindowMenu window
Global workarea=CreateCanvas(0,0,200,200,window)
SetBuffer CanvasBuffer(workarea)
ClsColor 0,0,0
Cls
Color 255,255,255
;Event loop - only two will do for the purpose of this example
While WaitEvent()
Select EventID()
Case $803
End
Case $1001
If EventData()=11 Then doloop()
End Select
Wend
;Slow operation involving lots of calculation
;but interruptible by ESC
Function doloop()
FlushKeys
For i=0 To 100000
;Show that the operation is actually doing something
If (i Mod 1000)=0 Then
Cls
Text 20,20,Str(i)
FlipCanvas workarea
EndIf
For j=0 To 100000
k=i*j
Next
If GetKey()=27 Then Exit
Next
End Function