KeyboardReleased()

Syntax

Result = KeyboardReleased(KeyID)
Description
Checks if the specified key has been pushed and released. This function is useful for switch key checks, like a 'Pause' key in a game (one time the game is paused, next time it will continue). The function ExamineKeyboard() must be called before this function to update the keyboard state.

Parameters

KeyID The identifier of the key to be checked. For a full list of available keys see KeyboardPushed().

Return value

Nonzero if the specified key has been pushed and released, zero otherwise.

Example

  Debug "The sprite will only move when the key are released"

  OpenScreen(800, 600, 32, "Test")
  
  Procedure RenderFrame()
    Static x, y
    
    ClearScreen(RGB(0, 0, 0))
    
    If ExamineKeyboard()
      If KeyboardReleased(#PB_Key_Left)
        x-10
      ElseIf KeyboardReleased(#PB_Key_Right)
        x+10
      EndIf
      
      If KeyboardReleased(#PB_Key_Up)
        y-10
      ElseIf KeyboardReleased(#PB_Key_Down)
        y+10
      EndIf
      
      DisplaySprite(0, x, y)
    EndIf
    
    FlipBuffers(); // continue the rendering
  EndProcedure
  
  Procedure Loading(Type, Filename$, ObjectId)
    Static NbLoadedElements
    
    NbLoadedElements+1
    If NbLoadedElements = 1 ; The loading of all images and sounds is finished, we can start the rendering
      FlipBuffers(); // start the rendering
    EndIf
  EndProcedure
  
  Procedure LoadingError(Type, Filename$, ObjectId)
    Debug Filename$ + ": loading error"
  EndProcedure
  
  ; Register the loading event before calling any resource load command
  BindEvent(#PB_Event_Loading, @Loading())
  BindEvent(#PB_Event_LoadingError, @LoadingError())
  BindEvent(#PB_Event_RenderFrame, @RenderFrame())
  
  LoadSprite(0, "Data/SpiderBasicLogo.png")

See Also

ExamineKeyboard(), KeyboardPushed()

Supported OS

All

<- KeyboardPushed() - Keyboard Index