locked
Windows API? RRS feed

  • Question

  • Is there any way to incorporate the windows API into small basic to make programs look more proffessionaL? 
    Friday, January 9, 2009 2:20 PM

Answers

  • how can the graphics window take keyboard input?

    The GraphicsWindow uses KeyDown or KeyUp events along with LastKey.

    First you need to tell the program what to call when a key event happens.  This is done with -

      GraphicsWindow.KeyDown = OnKeyDown
    or you can also use
      GraphicsWindow.KeyUp = OnKeyUp

    (note: you can change the names of the subroutines to any name you like)

    Put one or both near the beginning of your program.  You only need to call them once in your program.  Every time a key is pressed, OnKeyDown will be called or if you use KeyUp, every time a key is released, OnKeyUp is called.

    OnKeyDown or OnKeyUp are subroutines you need to create.  This is where you can test GraphicsWindow.LastKey with a conditional statement or whatever code you wish to accomplish.

    GraphicsWindow.KeyDown = OnKeyDown  
    GraphicsWindow.KeyUp = OnKeyUp  
     
     
    Sub OnKeyDown  
      Key = GraphicsWindow.LastKey  
              
      If (Key = "C" Or Key = "c"Then 
        GraphicsWindow.Clear()  
      ElseIf (Key = "L" Or Key = "l"Then 
        GraphicsWindow.DrawLine(Math.GetRandomNumber(100), Math.GetRandomNumber(100), Math.GetRandomNumber(100), Math.GetRandomNumber(100))  
      ElseIf (Key = "N" Or Key = "n"Then 
        CallNSubroutine()  
      EndIf  
        
    EndSub  
     
    Sub OnKeyUp  
      'Clear Key to avoid erroneous calls  
      Key = "" 
    EndSub  
     
     
    Sub CallNSubroutine  
      GraphicsWindow.DrawText(Math.GetRandomNumber(100), Math.GetRandomNumber(100), "N")  
    EndSub  
     

     

    • Marked as answer by Vijaye Raji Wednesday, January 14, 2009 5:11 AM
    Sunday, January 11, 2009 1:16 AM

All replies

  • Currently there isn't a way, spike_132000.  We're not thinking of adding support for this feature at this point - because the target audience for Small Basic is beginners and creating professional programs would be lower in priority to the other features.
    Saturday, January 10, 2009 10:03 PM
  • Hey thanks for the reply, I never asked to make professional programs, I asked to make them LOOK more professional.

    also, how can the graphics window take keyboard input?

    eg, back in the day it looked something like,

    text$ = inkey$

    Saturday, January 10, 2009 10:52 PM
  • how can the graphics window take keyboard input?

    The GraphicsWindow uses KeyDown or KeyUp events along with LastKey.

    First you need to tell the program what to call when a key event happens.  This is done with -

      GraphicsWindow.KeyDown = OnKeyDown
    or you can also use
      GraphicsWindow.KeyUp = OnKeyUp

    (note: you can change the names of the subroutines to any name you like)

    Put one or both near the beginning of your program.  You only need to call them once in your program.  Every time a key is pressed, OnKeyDown will be called or if you use KeyUp, every time a key is released, OnKeyUp is called.

    OnKeyDown or OnKeyUp are subroutines you need to create.  This is where you can test GraphicsWindow.LastKey with a conditional statement or whatever code you wish to accomplish.

    GraphicsWindow.KeyDown = OnKeyDown  
    GraphicsWindow.KeyUp = OnKeyUp  
     
     
    Sub OnKeyDown  
      Key = GraphicsWindow.LastKey  
              
      If (Key = "C" Or Key = "c"Then 
        GraphicsWindow.Clear()  
      ElseIf (Key = "L" Or Key = "l"Then 
        GraphicsWindow.DrawLine(Math.GetRandomNumber(100), Math.GetRandomNumber(100), Math.GetRandomNumber(100), Math.GetRandomNumber(100))  
      ElseIf (Key = "N" Or Key = "n"Then 
        CallNSubroutine()  
      EndIf  
        
    EndSub  
     
    Sub OnKeyUp  
      'Clear Key to avoid erroneous calls  
      Key = "" 
    EndSub  
     
     
    Sub CallNSubroutine  
      GraphicsWindow.DrawText(Math.GetRandomNumber(100), Math.GetRandomNumber(100), "N")  
    EndSub  
     

     

    • Marked as answer by Vijaye Raji Wednesday, January 14, 2009 5:11 AM
    Sunday, January 11, 2009 1:16 AM
  • Thanks, that helped alot :D 
    Wednesday, January 14, 2009 10:48 AM