GraphicsWindow.LastKey
-
Monday, December 29, 2008 6:22 PMI created this small programm for getting keynames.
TextWindow.show()
GraphicsWindow.Show()
Start()
Sub Start
GraphicsWindow.KeyDown = onKeyDown
endsub
Sub onKeyDown
LK = GraphicsWindow.Lastkey
TextWindow.Writeline(LK)
Start()
EndSub
It allways douples the resultlines in the TextWindow.
e.g.Return
a.s.o.
A
A
Back
Back
Back
Back
Space
Space
Space
Space
Space
Space
Space
Space
What's the reason for that curiosity?
Answers
-
Monday, December 29, 2008 7:03 PMAnswerer
Your recursively calling Start(). So while you press a key, the program continuously calls the GraphicsWindow.LastKey event and writes to the screen. If you remove the call to Start() in the OnKeyDown subroutine, it will correct your problem.- Marked As Answer by Vijaye RajiOwner Monday, December 29, 2008 7:23 PM
-
Monday, December 29, 2008 11:51 PMAnswerer
RushWorks seems to have found the good solution but I'm unsure he have gived the good explaination about it.
The problem is that, when you look at compiled MSIL, GraphicsWindow.KeyDown = onKeyDown is compiled as AddHandler GraphicsWindow.KeyDown, AddressOf onKeyDown, so when you call start, you don't set the onKeyDown event, you add a new listener to this event. This explains why you go a 'Return', two 'A', four 'Back', height 'Space', ....
Maybe this behaviour should be changed because it can confuse users, but it seems to be difficult, unless we use Custom Events (in VB.NET, I don't know if there's any equivalent for C#) but then, it's unusual for 'pure' .NET developers. It's in fact the problem of the old JScript event model (adding 'onXXX' as attribute of an element). This problem was solved using an additional event system, which is not good for a simple language.
I hope I gived a good vision of the 'problem'.
Fremy VB & C#- Marked As Answer by Vijaye RajiOwner Tuesday, December 30, 2008 9:48 AM
All Replies
-
Monday, December 29, 2008 7:03 PMAnswerer
Your recursively calling Start(). So while you press a key, the program continuously calls the GraphicsWindow.LastKey event and writes to the screen. If you remove the call to Start() in the OnKeyDown subroutine, it will correct your problem.- Marked As Answer by Vijaye RajiOwner Monday, December 29, 2008 7:23 PM
-
Monday, December 29, 2008 11:51 PMAnswerer
RushWorks seems to have found the good solution but I'm unsure he have gived the good explaination about it.
The problem is that, when you look at compiled MSIL, GraphicsWindow.KeyDown = onKeyDown is compiled as AddHandler GraphicsWindow.KeyDown, AddressOf onKeyDown, so when you call start, you don't set the onKeyDown event, you add a new listener to this event. This explains why you go a 'Return', two 'A', four 'Back', height 'Space', ....
Maybe this behaviour should be changed because it can confuse users, but it seems to be difficult, unless we use Custom Events (in VB.NET, I don't know if there's any equivalent for C#) but then, it's unusual for 'pure' .NET developers. It's in fact the problem of the old JScript event model (adding 'onXXX' as attribute of an element). This problem was solved using an additional event system, which is not good for a simple language.
I hope I gived a good vision of the 'problem'.
Fremy VB & C#- Marked As Answer by Vijaye RajiOwner Tuesday, December 30, 2008 9:48 AM
-
Tuesday, December 30, 2008 6:52 AMHi Rushworks and FremyCompany,
Thank you very much !
Horst