Input function
BlitzPlus Forums/BlitzPlus Programming/Input function
| ||
hi ! i've an image background and use a bitmap font. No problem to display a message. Now, I just want that the player input his name (eventually use backspace) ! I've tried many examples from the code archive, but no success. Is somebody have a solid code example to do that ? Many thanks ! |
| ||
Oh. This is much work. You have to test every key with a character that is allowed and add it to a string. before adding you have to test if "Shift" was pressed and add the Capital character. The function will not be very big if you are going to use arrays. But you have to copy all letters with their Scancodes into you array. |
| ||
Thanks Peer, maybe exist an better solution, but in my case the following code seems to work...Function GUI_EditText (PosX, PosY, Message$, MinLength, MaxLength, Value$, hImage) Elapsedtime = MilliSecs() GUI_Display_text (PosX,PosY, Message$ + Value$) While Not KeyDown (28) And Len(Value$) >= MinLength Flip If (MilliSecs() > Elapsedtime + 50) Then Elapsedtime = MilliSecs() If KeyDown(14) Then If Len(Value$) > 0 Then Value$ = Left$(Value$, Len(Value$) -1) End If Else KeyValue = GetKey() Char$ = Chr$(KeyValue) If Len(Value$) < MaxLength Then If (KeyValue => 48 And KeyValue <=57) Or (KeyValue => 65 And KeyValue <= 90) Or (KeyValue => 97 And KeyValue <= 122) Then Value$ = Value$ + Lower(Char$) Else ; If Not ( KeyDown (14) Or KeyDown(28)) Then play a sound End If End If End If End If If Len(Value$) <= (MinLength-1) And KeyDown (28) Then ; play a sound !!! End If DrawImage hImage, 0, 0 GUI_Display_text (PosX, PosY, Message$ + Value$ + "|") Wend End Function |
| ||
I was going to say the command you want is GetKey but you're already using that as the core of your GUI code. Peer, it sounds like you think you have to test every single key using KeyDown or KeyHit which is not the case. Those are designed for checking a single specific key. To allow text input (ie. receiving input from any key on the keyboard) use GetKey. |
| ||
When you write text to a graphical screen, you probably have noticed that overlapping text does not cancel the earlier text, you just get a clustering of lines and points from all the text drawn at that point. It is the product of using an OR'ing process to add new data to the screen. The backspace or delete command is intended to replace prior text with a blank, and instead of two or more characters being displayed at each position, you want the latest character to display all by itself. So how do you manage this? One way is to define a viewport that is positioned exactly where that next character should go and use CLS to wipe out the content that might already be there. Then when a valid key is pressed, you write the corresponding character to that spot. By juggling the placement and size of the viewport and using CLS when necessary, you can cause your routine to behave in the manner you expect. |