KeyboardInkey()

Syntax

String$ = KeyboardInkey()
Description
Returns the last typed character, very useful when keyboard input is required within a gaming application, such as the name in highscore, in game console, etc.).

Parameters

None.

Return value

The last typed character.

Example

  OpenScreen(800, 600, 32, "Test")
  
  Procedure RenderFrame()
    Static x, y, FullText$
    
    ClearScreen(RGB(0, 0, 0))
    
    If ExamineKeyboard()
      ; If we press the 'Back' key, we will delete the last character
      ;
      If KeyboardReleased(#PB_Key_Back)
        FullText$ = Left(FullText$, Len(FullText$)-1)
      Else
        Result$ = KeyboardInkey()
        If FindString("1234567890 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Result$) ; Or your chosen valid characters
          FullText$ + Result$
          Debug FullText$
        EndIf ; Add the new text to the current one (if any)
      EndIf
    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()
<- InitKeyboard() - Keyboard Index - KeyboardPushed() ->