locked
Arrow Controls RRS feed

  • Question

  • Yes, I know everyone is tired of this, but I can't seem to get it. I have the code: 

     

    GraphicsWindow.Show()
    GraphicsWindow.Top = "0"
    GraphicsWindow.Width = "1699"
    GraphicsWindow.Height = "972"
    GraphicsWindow.Left = "0"
    If GraphicsWindow.LastKey = "left" Then
      Sound.PlayBellRing()
      EndIf

    Will someone tell me why it's not responding? Thanks so much!

    Tuesday, February 11, 2014 1:15 AM

Answers

  • ReggieFilsAime,

    The problem is your program is ending before you hit the key.  Try the below program.  Run it and hit the "Left key".  It will show left in the graphics window and the bell will ring.  Then hit another key (spacebar).  Then hit the left key again.

    Also, the first letter that the key shows is always capitalized.

    GraphicsWindow.Show()
    GraphicsWindow.Top = "0"
    GraphicsWindow.Width = "1699"
    GraphicsWindow.Height = "972"
    GraphicsWindow.Left = "0"
    While "True"
      If GraphicsWindow.LastKey = "Left" Then
        GraphicsWindow.DrawText(0,0,GraphicsWindow.lastkey)
         sound.playbellringAndWait()   
    endif
    EndWhile


    JR

    • Proposed as answer by litdev Wednesday, February 12, 2014 11:11 PM
    • Marked as answer by Nonki Takahashi Wednesday, March 5, 2014 9:11 AM
    Tuesday, February 11, 2014 2:16 AM
    Answerer
  • Or you can use a Key Event:

    GraphicsWindow.Show()
    GraphicsWindow.Top = "0"
    GraphicsWindow.Width = "1699" 'can use Desktop.width here
    GraphicsWindow.Height = "972"
    GraphicsWindow.Left = "0"
    
    GraphicsWindow.KeyDown = OnKeyDown
    
    Sub OnKeyDown
      If GraphicsWindow.LastKey = "Left" Then
        Sound.PlayBellRing()
      EndIf
    EndSub


    • Edited by Jibba j Tuesday, February 11, 2014 4:57 PM
    • Proposed as answer by litdev Wednesday, February 12, 2014 11:11 PM
    • Marked as answer by Nonki Takahashi Wednesday, March 5, 2014 9:11 AM
    Tuesday, February 11, 2014 4:56 PM

All replies

  • ReggieFilsAime,

    The problem is your program is ending before you hit the key.  Try the below program.  Run it and hit the "Left key".  It will show left in the graphics window and the bell will ring.  Then hit another key (spacebar).  Then hit the left key again.

    Also, the first letter that the key shows is always capitalized.

    GraphicsWindow.Show()
    GraphicsWindow.Top = "0"
    GraphicsWindow.Width = "1699"
    GraphicsWindow.Height = "972"
    GraphicsWindow.Left = "0"
    While "True"
      If GraphicsWindow.LastKey = "Left" Then
        GraphicsWindow.DrawText(0,0,GraphicsWindow.lastkey)
         sound.playbellringAndWait()   
    endif
    EndWhile


    JR

    • Proposed as answer by litdev Wednesday, February 12, 2014 11:11 PM
    • Marked as answer by Nonki Takahashi Wednesday, March 5, 2014 9:11 AM
    Tuesday, February 11, 2014 2:16 AM
    Answerer
  • Or you can use a Key Event:

    GraphicsWindow.Show()
    GraphicsWindow.Top = "0"
    GraphicsWindow.Width = "1699" 'can use Desktop.width here
    GraphicsWindow.Height = "972"
    GraphicsWindow.Left = "0"
    
    GraphicsWindow.KeyDown = OnKeyDown
    
    Sub OnKeyDown
      If GraphicsWindow.LastKey = "Left" Then
        Sound.PlayBellRing()
      EndIf
    EndSub


    • Edited by Jibba j Tuesday, February 11, 2014 4:57 PM
    • Proposed as answer by litdev Wednesday, February 12, 2014 11:11 PM
    • Marked as answer by Nonki Takahashi Wednesday, March 5, 2014 9:11 AM
    Tuesday, February 11, 2014 4:56 PM
  • Thanks so much you guys. I'll be posting my next problem soon :D
    Wednesday, February 12, 2014 11:09 PM