KeyboardInkey()

语法

String$ = KeyboardInkey()
概要
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.).

参数

无.

返回值

The last typed character.

示例

  If InitSprite() And InitKeyboard() And OpenScreen(800, 600, 32, "")
    Repeat
      FlipBuffers()
      ClearScreen(RGB(0, 0, 0))
     
      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$
        EndIf ; Add the new text to the current one (if any)
      EndIf
     
      ; Display the result
      ;
      If StartDrawing(ScreenOutput())
          DrawingMode(1)
          FrontColor(RGB(128, 255, 0))
          DrawText(20, 20, "Just type some text...:")
          DrawText(20, 40, FullText$)
        StopDrawing()
      EndIf
    Until KeyboardPushed(#PB_Key_Escape)
  EndIf

参阅

ExamineKeyboard()

已支持操作系统

所有

<- InitKeyboard() - Keyboard Index - KeyboardMode() ->