none
Is it possible to "reset" GraphicsWindow.LastKey? RRS feed

  • Question

  • I've been messing around in SmallBASIC (as you do when bored) and made a pretty basic program that lists specs (with the help of Oskariok's Data Extension), and the window showing specs launches on a keypress. But, if I use the Goto statement, it goes back to the start and the popup window reopens, presumably because no other key has been pressed. Is it possible to either reset this, change it to a key that isn't one used for executing a bit of code, or is there another method that takes the program back to the start without it going in an endless loop?
    Saturday, October 1, 2011 7:09 PM

Answers

  • There is no way to reset it, but you can use a separate variable:

    key = ""

    graphicswindow.keydown=keydown

    sub keydown

        key = graphicswindow.keydown

        'perform operation here... 

        key=""
    endsub 


    ~~AirWaves!!~~
    • Edited by AirWaves Saturday, October 1, 2011 11:10 PM
    • Marked as answer by LMCSHERRY Sunday, October 2, 2011 11:05 AM
    Saturday, October 1, 2011 11:10 PM

All replies

  • There is no way to reset it, but you can use a separate variable:

    key = ""

    graphicswindow.keydown=keydown

    sub keydown

        key = graphicswindow.keydown

        'perform operation here... 

        key=""
    endsub 


    ~~AirWaves!!~~
    • Edited by AirWaves Saturday, October 1, 2011 11:10 PM
    • Marked as answer by LMCSHERRY Sunday, October 2, 2011 11:05 AM
    Saturday, October 1, 2011 11:10 PM
  • It is almost certainly possible to do what you want - the problem is I'm not sure exactly what you want to do or where you are starting from, and it is hard to make suggestions that would be helpful - they probably wouldn't be described as a way to "reset the GraphicsWindow.LastKey", but probably something on the lines of using events and While loops.

    The goto will just do that, send the code where the goto is set - whether that is an endless loop or not depends on whether there is an exit path for the code to get out of the endless loop, in which case perhaps a While loop may be a better approach - again it depends to large extent on what code you have so far and what your thinking was to do it the way you are, which then forms a starting point to provide constructive help.

    AirWaves's suggestion using the event is good and perhaps does the job, if not post a short code you are working on and what it doesn't do that you want it to.

    Sunday, October 2, 2011 10:55 AM
    Moderator
  • There is no way to reset it, but you can use a separate variable:

    key = ""

    graphicswindow.keydown=keydown

    sub keydown

        key = graphicswindow.keydown

        'perform operation here... 

        key=""
    endsub 


    ~~AirWaves!!~~

    That gave some errors ("Cannot find property KeyDown in GraphicsWindow" or similar), so I revised it a bit to the following:

     

    start:
    key = ""
    GraphicsWindow.KeyDown = keydown
    
    Sub keydown
      key = GraphicsWindow.LastKey
      If key = "Space" Then
        TextWindow.WriteLine(Clock.Time)
        Program.Delay(500)
        TextWindow.Hide()
        key = ""
        Goto start
      EndIf
      EndSub

    The writing of the time being the operation, as an example.

    Sunday, October 2, 2011 11:08 AM
  • Be careful not to do a GoTo jump into or out of subroutines - you get away with it here (it doesn't actually do the GoTo jump, but doesn't crash either), but in general it is likely to cause a stack corruption crash.

    Also, you don't need to keep registering the event with this "GraphicsWindow.KeyDown = keydown" - once it is done once the event will fire whenever a key is pressed, so all you need is:

     

    GraphicsWindow.KeyDown = keydown
    
    Sub keydown
      key = GraphicsWindow.LastKey
      If key = "Space" Then
        TextWindow.WriteLine(Clock.Time)
        Program.Delay(500)
        TextWindow.Hide()
      EndIf
    EndSub


     


    Sunday, October 2, 2011 2:08 PM
    Moderator