Купить

 

Ввод текста в DarkBasic

SYNC ON
SYNC RATE 0
TRUE=1
FALSE=0

REM The following constants are to recognise the special keys.
REM (These are the scancode values for these keys)
backspace=14
tab=15
enter=28
left=203
right=205
del=211

chopping=FALSE
REM The chopping variable signifies whether an entry is truncated
REM at the cursor when ENTER is hit. If set to TRUE, characters after
REM the cursor are chopped off the entry. If FALSE, characters after
REM the cursor are included in the entry.


WaitRepeat=500 : REM repeating begins after key is held for 500 ms
RepeatSpeed=50 : REM repeating proceeds at 1 character per 50 ms


cursor$="[]"
REM You can use any character for the cursor. Decent ones are
REM The pipe: | The slash: / The backslash: \ or underscore: _
REM you can also use multiple characters, i.e. cursor$="[]"

entry$=""
postcursor$=""
RepeatSpeed=WaitRepeat-RepeatSpeed
finished=FALSE

REPEAT
key=scancode()
REM This the next big IF block checks if a special key is being pressed.
REM If it is, it runs the code for that key. If it's not, we grab INKEY$()

IF key=backspace OR key=left OR key=right OR key=del OR key=tab OR key=enter

IF key=backspace
IF SpecialKeyRepeat=FALSE
SpecialKeyRepeat=TRUE
RepeatTime=TIMER()
IF LEN(entry$) > 0 THEN entry$=LEFT$(entry$,LEN(entry$)-1)
REM The line above does all the work for the backspace key. Everything
REM else is just to test if the repeat code should run because of
REM a held key.
ELSE
IF (TIMER()-RepeatTime) > WaitRepeat
RepeatTime=TIMER()-RepeatSpeed
IF LEN(entry$) > 0 THEN entry$=LEFT$(entry$,LEN(entry$)-1)
ENDIF
ENDIF
ENDIF

IF key=left
IF SpecialKeyRepeat=FALSE
SpecialKeyRepeat=TRUE
RepeatTime=TIMER()
IF LEN(entry$) > 0
postcursor$=RIGHT$(entry$,1)+postcursor$
entry$=LEFT$(entry$,LEN(entry$)-1)
REM The two lines above are the code for the left key. First we
REM add the rightmost character of entry$ to postcursor$, and then
REM we subtract that character from entry$ by truncating it by
REM one character. "postcursor$" is simply the part of the entry
REM which comes after the current cursor position.
ENDIF
ELSE
IF (TIMER()-RepeatTime)>WaitRepeat
RepeatTime=TIMER()-RepeatSpeed
IF LEN(entry$) > 0
postcursor$=RIGHT$(entry$,1)+postcursor$
entry$=LEFT$(entry$,LEN(entry$)-1)
ENDIF
ENDIF
ENDIF
ENDIF

IF key=right
IF SpecialKeyRepeat=FALSE
SpecialKeyRepeat=TRUE
RepeatTime=TIMER()
IF LEN(postcursor$) > 0
entry$=entry$+LEFT$(postcursor$,1)
postcursor$=RIGHT$(postcursor$,LEN(postcursor$)-1)
ENDIF
ELSE
IF (TIMER()-RepeatTime)>WaitRepeat
RepeatTime=TIMER()-RepeatSpeed
IF LEN(postcursor$) > 0
entry$=entry$+LEFT$(postcursor$,1)
postcursor$=RIGHT$(postcursor$,LEN(postcursor$)-1)
ENDIF
ENDIF
ENDIF
ENDIF

IF key=del
IF SpecialKeyRepeat=FALSE
SpecialKeyRepeat=TRUE
RepeatTime=TIMER()
IF LEN(postcursor$) > 0
postcursor$=RIGHT$(postcursor$,LEN(postcursor$)-1)
REM The delete key is similar to the backspace key, except that
REM it removes characters AFTER the cursor instead of before it.
ENDIF
ELSE
IF (TIMER()-RepeatTime)>WaitRepeat
RepeatTime=TIMER()-RepeatSpeed
IF LEN(postcursor$) > 0
postcursor$=RIGHT$(postcursor$,LEN(postcursor$)-1)
ENDIF
ENDIF
ENDIF
ENDIF

IF key=enter
IF chopping=TRUE
FinishedEntry$=entry$
ELSE
FinishedEntry$=entry$+postcursor$
ENDIF
finished=TRUE
ENDIF

ELSE
REM This ELSE means "if a special key is not being pressed".
REM Now it's time to get the current character-key being pressed
REM and add it to entry$.
REM Also, since we now know that no special key is being held,
REM we can set SpecialKeyRepeat to FALSE.

SpecialKeyRepeat=FALSE
currentkey$=inkey$()
IF currentkey$=""
repeater$=""
ELSE
IF currentkey$ <> repeater$
entry$=entry$+currentkey$
repeater$=currentkey$
ENDIF
ENDIF
ENDIF


REM Now we display the current entry.
CLS
TEXT 0,0,entry$+cursor$+postcursor$
SYNC

UNTIL finished=TRUE

TEXT 0,100,"you entered:"
TEXT 0,120,FinishedEntry$
END

Hosted by uCoz