none
How do you use a certain key to load an image ie. the menu screen. RRS feed

  • Question

  • Hi

    I'm trying to program a game and on the main menu screen there are four options to choose from which I did along with the menu in Photoshop. My question is, how do you A: press a certain key to open one of the menus, or B: Click on one of the options to open the menu.

     

    Thanks

    Anidion

    Thursday, October 6, 2011 12:24 PM

Answers

  • OK, I understand.

    You need to use the KeyDown event and also the LastKey property - the event is fired when a key is pressed and LastKey holds the Key name that was pressed - you can then process that to move a ball etc.

    Simple example using arrow keys to move a ball - Import RFW981.

    You can get the name of a key pressed by the following test code:

    GraphicsWindow.KeyDown = OnKeyDown
    
    Sub OnKeyDown
      GraphicsWindow.Clear()
      GraphicsWindow.DrawText(100,100,GraphicsWindow.LastKey)
    EndSub

    • Marked as answer by Anidion Friday, October 7, 2011 3:35 PM
    Friday, October 7, 2011 3:15 PM
    Moderator

All replies

  • Sorry, this is the SmallBasic programming language forum.

    If this is a SmallBasic question please give more details and some sample code you are having issues with.

    Thursday, October 6, 2011 6:27 PM
    Moderator
  • This is a Small Basic question. I'm not having issues with any code, I just want to know how you A: press a certain key to open one of the menus, or B: Click on one of the options to open the menu.

     

    Thanks

    Anidion

    Friday, October 7, 2011 11:25 AM
  • Hi,

    If we mean the SmallBasic interface, when you start typing anything the intelisense wheel comes up and as you type the options narrow towards your command, at any stage press tab to select the current, or use the mouse wheel and left mouse.

    But I'm only guessing what menu/options/buttons you refer to.

    Friday, October 7, 2011 12:35 PM
    Moderator
  • I know about the wheel. The thing is, I know there is an event called, GraphicsWindow.Keydown, and I understand how to use that, but what I mean is a certain key, for example, pressing "W" to get a sprite to move.

     

    Thanks

    Anidion

    Friday, October 7, 2011 2:38 PM
  • OK, I understand.

    You need to use the KeyDown event and also the LastKey property - the event is fired when a key is pressed and LastKey holds the Key name that was pressed - you can then process that to move a ball etc.

    Simple example using arrow keys to move a ball - Import RFW981.

    You can get the name of a key pressed by the following test code:

    GraphicsWindow.KeyDown = OnKeyDown
    
    Sub OnKeyDown
      GraphicsWindow.Clear()
      GraphicsWindow.DrawText(100,100,GraphicsWindow.LastKey)
    EndSub

    • Marked as answer by Anidion Friday, October 7, 2011 3:35 PM
    Friday, October 7, 2011 3:15 PM
    Moderator
  • Thank you so much!
    Friday, October 7, 2011 3:34 PM
  • How do you get it to come up all in a row as if you were writing in a textbox, not just to overlap the other letters or to replace the other keys.

    For example, when i do it exactly as you have, each letter just replaces the last

    If i get rid of the clear() line then they all just overlap

    So how do i get them all to come up next to  each other?

    Thanks

    Friday, January 31, 2014 9:45 AM
  • If you mean litdev's test code:

    eg.

    String = ""
    GraphicsWindow.KeyDown = OnKeyDown

    Sub OnKeyDown
      String = Text.Append(String + " ", GraphicsWindow.LastKey)   ' Variant 1 using Text.Append
      'String = String + " " + GraphicsWindow.LastKey                      ' Variant 2 using only '+'
      GraphicsWindow.Clear()
      GraphicsWindow.DrawText(100,100,String)
    EndSub

    Friday, January 31, 2014 12:11 PM
    Answerer