KeyboardPushed()

Syntax

Result = KeyboardPushed(KeyID)
Description
Checks if the specified key is pressed. Any number of keys may be pressed at the same time. The function ExamineKeyboard() must be called before this function in order to update the keyboard state.

To check if a specified key has been pushed and released, see KeyboardReleased().

Parameters

KeyID The identifier of the key to be checked. List of available keys:
  #PB_Key_All   ; All keys are tested. Very useful for any key checks.

  #PB_Key_1
  #PB_Key_2
  #PB_Key_3
  #PB_Key_4
  #PB_Key_5
  #PB_Key_6
  #PB_Key_7
  #PB_Key_8
  #PB_Key_9
  #PB_Key_0

  #PB_Key_A
  #PB_Key_B
  #PB_Key_C
  #PB_Key_D
  #PB_Key_E
  #PB_Key_F
  #PB_Key_G
  #PB_Key_H
  #PB_Key_I
  #PB_Key_J
  #PB_Key_K
  #PB_Key_L
  #PB_Key_M
  #PB_Key_N
  #PB_Key_O
  #PB_Key_P
  #PB_Key_Q
  #PB_Key_R
  #PB_Key_S
  #PB_Key_T
  #PB_Key_U
  #PB_Key_V
  #PB_Key_W
  #PB_Key_X
  #PB_Key_Y
  #PB_Key_Z

  #PB_Key_Escape
  #PB_Key_Minus
  #PB_Key_Equals
  #PB_Key_Back
  #PB_Key_Tab
  #PB_Key_LeftBracket
  #PB_Key_RightBracket
  #PB_Key_Return
  #PB_Key_LeftControl
  #PB_Key_SemiColon
  #PB_Key_Apostrophe
  #PB_Key_Grave
  #PB_Key_LeftShift
  #PB_Key_BackSlash
  #PB_Key_Comma
  #PB_Key_Period
  #PB_Key_Slash
  #PB_Key_RightShift
  #PB_Key_Multiply
  #PB_Key_LeftAlt
  #PB_Key_Space
  #PB_Key_Capital
  #PB_Key_F1
  #PB_Key_F2
  #PB_Key_F3
  #PB_Key_F4
  #PB_Key_F5
  #PB_Key_F6
  #PB_Key_F7
  #PB_Key_F8
  #PB_Key_F9
  #PB_Key_F10
  #PB_Key_F11
  #PB_Key_F12
  #PB_Key_NumLock
  #PB_Key_Scroll
  #PB_Key_Pad0
  #PB_Key_Pad1
  #PB_Key_Pad2
  #PB_Key_Pad3
  #PB_Key_Pad4
  #PB_Key_Pad5
  #PB_Key_Pad6
  #PB_Key_Pad7
  #PB_Key_Pad8
  #PB_Key_Pad9
  #PB_Key_Add
  #PB_Key_Subtract
  #PB_Key_Decimal
  #PB_Key_PadEnter
  #PB_Key_RightControl
  #PB_Key_PadComma
  #PB_Key_Divide
  #PB_Key_RightAlt
  #PB_Key_Pause
  #PB_Key_Home
  #PB_Key_Up
  #PB_Key_Down
  #PB_Key_Left
  #PB_Key_Right
  #PB_Key_End
  #PB_Key_PageUp
  #PB_Key_PageDown
  #PB_Key_Insert
  #PB_Key_Delete

Return value

Nonzero if the specified key is pushed, zero otherwise.

Example

  OpenScreen(800, 600, 32, "Test")
  
  Procedure RenderFrame()
    Static x, y
    
    ClearScreen(RGB(0, 0, 0))
    
    If ExamineKeyboard()
      If KeyboardPushed(#PB_Key_Left)
        x-2
      ElseIf KeyboardPushed(#PB_Key_Right)
        x+2
      EndIf
      
      If KeyboardPushed(#PB_Key_Up)
        y-2
      ElseIf KeyboardPushed(#PB_Key_Down)
        y+2
      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(), KeyboardReleased()

Supported OS

All

<- KeyboardInkey() - Keyboard Index - KeyboardReleased() ->