Repeating Keystrokes
Blitz3D Forums/Blitz3D Programming/Repeating Keystrokes
| ||
HelloIf KY<>0 And KY=8 If Len(F_TXT)>0 F_TXT=Left$(F_TXT,Len(F_TXT)-1):CH=CH-1 EndIf ElseIf KY<>0 And KY>13 And CH<=MAX_CH F_TXT$=F_TXT$+Chr(KY):CH=CH+1 EndIf Using this code, I wanted to be pointed to a link that demonstrates the use of repeating keystrokes so I can hold the delete key to remove text without repeatedly tapping the keys. Thanks * This is the timing code I have thus far ST=MilliSecs() .RK If CH=8 And Len(T$)>0 T$=Left$(T$,Len(T$)-1):If MilliSecs()-ST>250 Goto RK ElseIf CH>65 And CH<121 T$=T$+Chr$(CH) EndIf* |
| ||
You didnt specify which input function you use, but it looks to be GetChar(), so you should use KeyDown() instead. In any case, its probably best to encapsulate it in its own function, something like this: |
| ||
I am using GETKEY(). Here's what I have.Repeat Cls:KY=GetKey() If KY<>0 And KY=8 If Len(F_TXT)>0 F_TXT=Left$(F_TXT,Len(F_TXT)-1):CH=CH-1:DKT=MilliSecs() While KeyDown(14) If MilliSecs()-DKT>200 And Len(F_TXT)>0 F_TXT=Left$(F_TXT,Len(F_TXT)-1):CH=CH-1:DKT=MilliSecs() Text XX,YY,F_TXT$ ; If KY=13 Then Return F_TXT$:Exit Flip EndIf Wend ; goes here EndIf ElseIf KY<>0 And KY>13 And CH<=MAX_CH F_TXT$=F_TXT$+Chr(KY):CH=CH+1 EndIf Text XX,YY,F_TXT$ If KY=13 Then Return F_TXT$:Exit Flip Forever |
| ||
I am using GETKEY() Ah yes, im a blitzmax guy so used the wrong name, but its the same functionality :)Well it works.. But i had to move the drawing out of the test in the inner loop and add a cls. Though i would advise against that inner loop. You should really try to do this in a re-entrant fashion, and keep various states that the outer loop controls. Also, drawing in the midst of all this isnt necessary. Keeping the input logic separate will make things simpler and faster. |
| ||
Using this code now:Repeat Cls:KY=GetKey() If KY=8 And Len(F_TXT)>0 And BSH=0 F_TXT=Left$(F_TXT,Len(F_TXT)-1):CH=CH-1:DKT=MilliSecs():BSH=1 ElseIf KY=8 And Len(F_TXT)>0 And BSH=1 ; While KeyDown(14) If MilliSecs()-DKT>350 And Len(F_TXT)>0 F_TXT=Left$(F_TXT,Len(F_TXT)-1):CH=CH-1:DKT=MilliSecs() EndIf ; Wend ElseIf KY>13 And Len(F_TXT$)<=MAX_CH And CH<127 F_TXT$=F_TXT$+Chr(KY):CH=CH+1:BSH=0 EndIf ; SHWTXT() Text XX,YY,F_TXT$ Flip:CH=0 If KY=13 Then Return F_TXT$:Exit Forever I'm still missing it somewhere for some reason |
| ||
Your getting there :) The introduction of those states helps, though since its now re-entrant dont forget that any local variables (like KY) will not have the same value anymore. Im adding the needed changes below, since explaining code isnt always easy hehe Repeat Cls:KY=GetKey() If KY=8 And Len(F_TXT)>0 And BSH=0 F_TXT=Left$(F_TXT,Len(F_TXT)-1):CH=CH-1:DKT=MilliSecs():BSH=1 ElseIf KY=0 And Len(F_TXT)>0 And BSH=1 ; <-- check for 0 instead, or it will never enter or lose keys if no check If KeyDown(14) ; <-- used If instead of While, since this is now re-entrant If MilliSecs()-DKT>350 And Len(F_TXT)>0 F_TXT=Left$(F_TXT,Len(F_TXT)-1):CH=CH-1:DKT=MilliSecs() EndIf Else BSH=0 ; <-- reset state here since key is no longer down EndIf ElseIf KY>13 And Len(F_TXT$)<=MAX_CH And CH<127 F_TXT$=F_TXT$+Chr(KY):CH=CH+1:BSH=0 EndIf ; SHWTXT() Text XX,YY,F_TXT$ Flip:CH=0 If KY=13 Then Exit Forever |