It is currently Wed Jun 20, 2018 10:35 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: KeyboardInkey() can return two characters
PostPosted: Wed Jan 31, 2018 7:57 pm 
Offline
User
User

Joined: Mon Aug 13, 2012 7:26 am
Posts: 24
The Help states that it returns the last typed character, but fast typists will occasionally get two characters. This repros on Windows 8.1 and Windows 10, on PB 5.61 and PB 5.62beta2. The code below is copy/pasted from the KeyboardInkey() help section. I added the "If Len(result$) > 1" block to illustrate the bug. Simply execute the code and then type very quickly. You can also try to just mash keys as quickly as possible. I work around this now by testing for Left(Result$, 1).

Code:
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 Len(result$) > 1    ;I added this
          Debug result$
        EndIf
       
        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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye