aInput

Blitz3D Forums/Blitz3D Programming/aInput

This ia a little library that simulate a basic Input command in a loop...

Tell me what you think aout it...

;=========================================================================
; aInput
;=========================================================================

Const aInpUpperChars$  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Const aInpLowerChars$  = "abcdefghijklmnopqrstuvwxyz"
Const aInpAlphaChars$  = "1234567890"
Const aInpMathChars$   = "+-*/%<=>²"
Const aInpPunctChars$  = ".,:!?;'()"
Const aInpAccentChars$ = "àéèëêïîôöùûüçñ"
Const aInpMiscChars$   = "&#{[|_\@]}$£§µ¤"

Const aInpDefChars$ = aInpUpperChars$ + aInpLowerChars$ + aInpAlphaChars$ + aInpPunctChars$ + aInpMathChars$ + aInpMiscChars$ + aInpAccentChars$

Global aInpSCDelay1% = 15
Global aInpSCDelay2% = 3

Global aInpActiveHandle% = 0
Global aInpScanCode% = 0, aInpScanDelay% = 0, aInpScanFlag% = 0

Type TBlinker
	Field vis_count%
	Field hid_count%
	Field stp%
End Type

Type aInpObj
	Field txt$
	Field chars$
	Field allowSpace%
	Field allowCursor%
	Field allowBackSpace%
	Field allowDel%
	Field allowNumPad%
	Field allowSelection%
	Field maxChars%
	Field cpos%
	Field selpos%
End Type

Function CreateBlinker(visible% = 10, hidden% = 10)
	Local oblnk.TBlinker
	
	oblnk = New TBlinker
	If visible < 0 Then visible = 0
	If hidden < 0 Then hidden = 0
	oblnk\vis_count = visible
	oblnk\hid_count = hidden
	oblnk\stp = 0
	Return Handle(oblnk)
End Function

Function ResetBlinker%(hblnk%)
	Local oblnk.TBlinker
	
	oblnk = Object.TBlinker(hblnk)
	If oblnk = Null Then Return False
	oblnk\stp = 0
End Function

Function SetBlinker%(hblnk%, visible%, hidden%)
	Local oblnk.TBlinker
	
	oblnk = Object.TBlinker(hblnk)
	If oblnk = Null Then Return False
	If visible < 0 Then visible = 0
	If hidden < 0 Then hidden = 0
	oblnk\vis_count = visible
	oblnk\hid_count = hidden
	Return True
End Function

Function Blink%(hblnk%)
	Local oblnk.TBlinker
	Local result%
	
	oblnk = Object.TBlinker(hblnk)
	If oblnk = Null Then Return -1
	If oblnk\vis_count = 0 And oblnk\hid_count = 0 Then Return True
	If oblnk\vis_count > 0 And oblnk\hid_count = 0 Then Return True
	If oblnk\vis_count = 0 And oblnk\hid_count > 0 Then Return False
	
	If oblnk\stp < oblnk\vis_count Then
		oblnk\stp = oblnk\stp + 1
		Return True
	ElseIf oblnk\stp < oblnk\vis_count + oblnk\hid_count Then
		oblnk\stp = oblnk\stp + 1
		Return False
	Else
		oblnk\stp = 1
		Return True
	EndIf
End Function

Function FreeBlinker%(hblnk%)
	Local oblnk.TBlinker
	
	oblnk = Object.TBlinker(hblnk)
	If oblnk = Null Then Return False
	Delete oblnk
	Return True
End Function

Function FreeBlinkers()
	Local oblnk.TBlinker
	
	For oblnk = Each TBlinker
		Delete oblnk
	Next
End Function

Function aInpCreate%(txt$ = "")
	Local oinp.aInpObj
	
	oinp = New aInpObj
	oinp\txt$ = txt$
	oinp\chars$ = aInpDefChars$ + Chr$(34)
	oinp\cpos = Len(oinp\txt$)
	oinp\allowSpace = True
	oinp\allowCursor = True
	oinp\allowBackSpace = True
	oinp\allowDel = True
	oinp\allowNumPad = True
	oinp\allowSelection = False
	oinp\maxChars = 255
	oinp\selpos = -1
	aInpActiveHandle = Handle(oinp)
	Return aInpActiveHandle
End Function

Function aInpSetKeyDelay(delay1%, delay2%)
	aInpSCDelay1 = delay1
	aInpSCDelay2 = delay2
End Function

Function aInpAllowSpace%(hinp%, flag%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	oinp\allowSpace = flag
	Return True
End Function

Function aInpAllowCursor%(hinp%, flag%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	oinp\allowCursor = flag
	Return True
End Function

Function aInpAllowDel%(hinp%, flag%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	oinp\allowDel = flag
	Return True
End Function

Function aInpAllowBackSpace%(hinp%, flag%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	oinp\allowBackSpace = flag
	Return True
End Function

Function aInpAllowNumPad%(hinp%, flag%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	oinp\allowNumPad = flag
	Return True
End Function

Function aInpAllowSelection%(hinp%, flag%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	If flag = False
		If oinp\allowSelection = True Then oinp\selpos = -1
	EndIf
	oinp\allowSelection = flag
	Return True
End Function

Function aInpSetActive%(hinp%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	If hinp <> aInpActiveHandle Then
		oinp\selpos = -1
	EndIf
	aInpActiveHandle = hinp
	FlushKeys
	Return True
End Function

Function aInpGetActive%()
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(aInpActiveHandle)
	If oinp = Null Then Return 0
	Return aInpActiveHandle
End Function

Function aInpSetCharsNumber%(hinp%, cnum%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	If cnum < 0 Then cnum = 0
	oinp\maxChars = cnum
	Return True
End Function

Function aInpGetCharsNumber%(hinp%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return -1
	Return oinp\maxChars
End Function

Function aInpGetCursorPos%(hinp%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return -1
	Return oinp\cpos
End Function

Function aInpSetCursorPos%(hinp%, cpos%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	If cpos < 0 Then cpos = 0
	If cpos > Len(oinp\txt$) Then cpos = Len(oinp\txt$)
	oinp\cpos = cpos
	Return True
End Function

Function aInpGetSelPos%(hinp%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return -1
	Return oinp\selpos
End Function

Function aInpSelStart%(hinp%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return -1
	If oinp\selpos = -1 Then Return oinp\cpos
	If oinp\cpos > oinp\selpos Then Return oinp\selpos
	Return oinp\cpos
End Function

Function aInpSelEnd%(hinp%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return -1
	If oinp\selpos = -1 Then Return oinp\cpos
	If oinp\cpos > oinp\selpos Then Return oinp\cpos
	Return oinp\selpos
End Function

Function aInpSelLength%(hinp%)
	Return aInpSelEnd(hinp) - aInpSelStart(hinp)
End Function

Function aInpSelect%(hinp%, selstart% = 0, selend% = -1)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	If selstart < 0 And selend < 0 Then
		oinp\selpos = oinp\cpos
	Else
		If selend < 0 Then
			oinp\cpos = Len(oinp\txt$)
			oinp\selpos = selstart
		ElseIf selstart < 0 Then
			oinp\selpos = Len(oinp\txt$)
			oinp\cpos = selend
		Else
			oinp\selpos = selstart
			oinp\cpos = selend
		EndIf
	EndIf
	Return True
End Function

Function aInpSetSelPos%(hinp%, pos%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	If pos < -1 Then pos = -1
	If pos > Len(oinp\txt$) Then pos = Len(oinp\txt$)
	oinp\selpos = pos
	Return True
End Function

Function aInpGetSelText$(hinp%)
	Local oinp.aInpObj, sel%
	
	sel = aInpSelStart(hinp)
	If sel < 0 Then Return "Null"
	Return Mid$(aInpGetText$(hinp), sel + 1, aInpSelLength(hinp))
End Function

Function aInpLeftText$(hinp%)
	Local sel%
	
	sel = aInpSelStart(hinp)
	If sel < 0 Then Return "Null"
	Return Mid$(aInpGetText$(hinp), 1, sel)
End Function

Function aInpRightText$(hinp%)
	Local sel%
	
	sel = aInpSelEnd(hinp)
	If sel < 0 Then Return "Null"
	Return Mid$(aInpGetText$(hinp), sel + 1, Len(aInpGetText$(hinp)) - sel + 1)
End Function

Function aInpSetSelText%(hinp%, txt$)
	Local oinp.aInpObj, cpos%, selpos%, s%, l%, r%
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	If oinp\selpos = -1 Then
		cpos = oinp\cpos
		selpos = oinp\cpos
	ElseIf oinp\selpos >= oinp\cpos Then
		cpos = oinp\cpos
		selpos = oinp\selpos
	Else
		cpos = oinp\selpos
		selpos = oinp\cpos
	EndIf
	s = selpos - cpos
	l = Len(oinp\txt$)
	r = l - s + Len(txt$)
	If r > oinp\maxChars Then Return -1
	oinp\txt$ = Mid$(oinp\txt$, 1, cpos) + txt$ + Mid$(oinp\txt$, selpos + 1, l - selpos + 1)
	oinp\cpos = cpos + Len(txt$)
	oinp\selpos = -1
	Return True
End Function

Function aInpSetChars%(hinp%, chars$)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	oinp\chars$ = chars$
	Return True
End Function

Function aInpTextLength%(hinp%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return -1
	Return Len(oinp\txt$)
End Function

Function aInpSetText%(hinp%, txt$, setsel% = True)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	oinp\txt$ = txt$
	If setsel = True Then
		oinp\cpos = Len(oinp\txt$)
		oinp\selpos = -1
	EndIf
	Return True
End Function

Function aInpGetText$(hinp%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return "Null"
	Return oinp\txt$
End Function

Function aInpUpdate%()
	Local oinp.aInpObj
	Local ascii%, l%
	
	oinp = Object.aInpObj(aInpActiveHandle)
	If oinp = Null Then Return -1
	
	l = Len(oinp\txt$)
	
	If l > oinp\maxChars Then
		oinp\txt$ = Left$(oinp\txt$, oinp\maxChars)
	EndIf
	If oinp\cpos > oinp\maxChars Then
		oinp\cpos = oinp\maxChars
	EndIf
	If oinp\selpos > oinp\maxChars Then
		oinp\selpos = oinp\maxChars
	EndIf
		
	ascii = GetKey()
	If KeyDown(181) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "/", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "/")
			EndIf
		EndIf
		ascii = 47
		aInpScanCode = 181
	ElseIf KeyDown(55) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "*", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "*")
			EndIf
		EndIf
		ascii = 42
		aInpScanCode = 55
	ElseIf KeyDown(74) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "-", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "-")
			EndIf
		EndIf
		ascii = 45
		aInpScanCode = 74
	ElseIf KeyDown(78) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "+", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "+")
			EndIf
		EndIf
		ascii = 43
		aInpScanCode = 78
	ElseIf KeyDown(156) And aInpScanCode = 0
		ascii = 13
		aInpScanCode = 156
	ElseIf KeyDown(71) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "7", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "7")
			EndIf
		EndIf
		ascii = 55
		aInpScanCode = 71
	ElseIf KeyDown(72) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "8", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "8")
			EndIf
		EndIf
		ascii = 56
		aInpScanCode = 72
	ElseIf KeyDown(73) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "9", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "9")
			EndIf
		EndIf
		ascii = 57
		aInpScanCode = 73
	ElseIf KeyDown(75) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "4", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "4")
			EndIf
		EndIf
		ascii = 52
		aInpScanCode = 75
	ElseIf KeyDown(76) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "5", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "5")
			EndIf
		EndIf
		ascii = 53
		aInpScanCode = 76
	ElseIf KeyDown(77) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "6", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "6")
			EndIf
		EndIf
		ascii = 54
		aInpScanCode = 77
	ElseIf KeyDown(79) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "1", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "1")
			EndIf
		EndIf
		ascii = 49
		aInpScanCode = 79
	ElseIf KeyDown(80) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "2", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "2")
			EndIf
		EndIf
		ascii = 50
		aInpScanCode = 80
	ElseIf KeyDown(81) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "3", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "3")
			EndIf
		EndIf
		ascii = 51
		aInpScanCode = 81
	ElseIf KeyDown(82) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, "0", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, "0")
			EndIf
		EndIf
		ascii = 48
		aInpScanCode = 82
	ElseIf KeyDown(83) And aInpScanCode = 0
		If oinp\allowNumPad And Instr(oinp\chars$, ".", 1) > 0 Then
			If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
				aInpInternalStringAdd(oinp, ".")
			EndIf
		EndIf
		ascii = 46
		aInpScanCode = 83
	ElseIf Instr(oinp\chars$, Chr$(ascii), 1) > 0
		If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
			aInpInternalStringAdd(oinp, Chr$(ascii))
		EndIf
	ElseIf ascii = 32 And oinp\allowSpace Then
		If l < oinp\maxChars Or (oinp\allowSelection And oinp\selpos <> -1) Then
			aInpInternalStringAdd(oinp, " ")
		EndIf
	ElseIf KeyDown(14) And (aInpScanCode = 14 Or aInpScanCode = 0)
		If aInpScanCode = 0 Or aInpScanCode = 14 Then
			If aInpScanCode <> 14 Then
				aInpScanDelay = 0 : aInpScanFlag = 0
			EndIf
			If aInpScanDelay = 0 Then
				If oinp\allowBackSpace Then
					If oinp\cpos > 0 Or (oinp\allowSelection And oinp\selpos <> -1) Then
						aInpInternalStringAdd(oinp, "BackSpace")
					EndIf
				EndIf	
				If aInpScanFlag = 0 Then
					aInpScanDelay = aInpSCDelay1
					aInpScanFlag = 1
				Else
					aInpScanDelay = aInpSCDelay2
				EndIf
				ascii = 8
			Else
				aInpScanDelay = aInpScanDelay - 1
			EndIf	
			aInpScanCode = 14
		EndIf
	ElseIf KeyDown(203) And (aInpScanCode = 203 Or aInpScanCode = 0)
		If aInpScanCode = 0 Or aInpScanCode = 203 Then
			If aInpScanCode <> 203 Then
				aInpScanDelay = 0 : aInpScanFlag = 0
			EndIf
			If aInpScanDelay = 0 Then
				If oinp\allowCursor Then
					If oinp\allowSelection
						If KeyDown(42) Then
							If oinp\selpos = -1 Then oinp\selpos = oinp\cpos
						Else
							oinp\selpos = -1
						EndIf
					Else
						oinp\selpos = -1
					EndIf
					If oinp\cpos > 0 Then
						oinp\cpos = oinp\cpos - 1
					EndIf
				EndIf	
				If aInpScanFlag = 0 Then
					aInpScanDelay = aInpSCDelay1
					aInpScanFlag = 1
				Else
					aInpScanDelay = aInpSCDelay2
				EndIf
				ascii = 31
			Else
				aInpScanDelay = aInpScanDelay - 1
			EndIf	
			aInpScanCode = 203
		EndIf
	ElseIf KeyDown(205) And (aInpScanCode = 205 Or aInpScanCode = 0)
		If aInpScanCode = 0 Or aInpScanCode = 205 Then
			If aInpScanCode <> 205 Then
				aInpScanDelay = 0 : aInpScanFlag = 0
			EndIf
			If aInpScanDelay = 0 Then
				If oinp\allowSelection
					If KeyDown(42) Then
						If oinp\selpos = -1 Then oinp\selpos = oinp\cpos
					Else
						oinp\selpos = -1
					EndIf
				Else
					oinp\selpos = -1
				EndIf
				If oinp\allowCursor Then
					If oinp\cpos < l Then
						oinp\cpos = oinp\cpos + 1
					EndIf
				EndIf	
				If aInpScanFlag = 0 Then
					aInpScanDelay = aInpSCDelay1
					aInpScanFlag = 1
				Else
					aInpScanDelay = aInpSCDelay2
				EndIf
				ascii = 30
			Else
				aInpScanDelay = aInpScanDelay - 1
			EndIf	
			aInpScanCode = 205
		EndIf
	ElseIf KeyDown(211) And (aInpScanCode = 211 Or aInpScanCode = 0)
		If aInpScanCode = 0 Or aInpScanCode = 211 Then
			If aInpScanCode <> 211 Then
				aInpScanDelay = 0 : aInpScanFlag = 0
			EndIf
			If aInpScanDelay = 0 Then
				If oinp\allowDel Then
					If oinp\cpos < l Or (oinp\allowSelection And oinp\selpos <> -1) Then
						aInpInternalStringAdd(oinp, "Del")
					EndIf
				EndIf	
				If aInpScanFlag = 0 Then
					aInpScanDelay = aInpSCDelay1
					aInpScanFlag = 1
				Else
					aInpScanDelay = aInpSCDelay2
				EndIf
				ascii = 4
			Else
				aInpScanDelay = aInpScanDelay - 1
			EndIf	
			aInpScanCode = 211
		EndIf	
	EndIf
	
	If KeyDown(aInpScanCode) = False Then
		aInpScanCode = 0
		aInpScanDelay = 0
	EndIf
	Return ascii
End Function

Function aInpFree%(hinp%)
	Local oinp.aInpObj
	
	oinp = Object.aInpObj(hinp)
	If oinp = Null Then Return False
	Delete oinp
	Return True
End Function

Function aInpFreeAll()
	Local oinp.aInpObj
	
	For oinp = Each aInpObj
		Delete oinp
	Next
End Function

Function aInpInternalStringAdd(oinp.aInpObj, char$)
	Local cpos%, selpos%, inc%
	
	inc = 1
	If oinp\allowSelection And oinp\selpos <> -1 Then
		If oinp\selpos >= oinp\cpos Then
			cpos = oinp\cpos
			selpos = oinp\selpos
		ElseIf oinp\selpos < oinp\cpos Then
			cpos = oinp\selpos
			selpos = oinp\cpos
		EndIf
		If char$ = "BackSpace" Or char$ = "Del" Then
			If cpos = selpos Then
				If char$ = "BackSpace" Then
					If cpos > 0 Then
						cpos = cpos - 1
					EndIf
				Else
					If selpos < Len(oinp\txt$)
						selpos = selpos + 1
					EndIf
				EndIf
			EndIf
			char$ = ""
			inc = 0
		EndIf
	Else
		cpos = oinp\cpos
		selpos = oinp\cpos
		If char$ = "BackSpace" Then
			char$ = ""
			If cpos > 0 Then
				cpos = cpos - 1
				inc = -1
			Else
				inc = 0
			EndIf
		EndIf
		If char$ = "Del" Then
			char$ = ""
			If cpos < Len(oinp\txt$) Then
				selpos = selpos + 1
				inc = 0
			Else
				inc = 0
			EndIf
		EndIf
	EndIf
	oinp\txt$ = Left$(oinp\txt$, cpos) + char$ + Mid$(oinp\txt$, selpos + 1, Len(oinp\txt$) - selpos + 1)
	If oinp\allowSelection And oinp\selpos <> -1 Then
		oinp\cpos = cpos
		oinp\selpos = -1
	EndIf
	oinp\cpos = oinp\cpos + inc
End Function
	
; Demo
;-------------------
Graphics 640, 480
SetBuffer BackBuffer()

Global fnt_Comics% = LoadFont("Comic sans MS", 24, 0, 0, 0)
SetFont fnt_Comics

Global x% = 320, y% = 240, xinc% = 2, yinc% = 2
Delay 1000
Global inp% = aInpCreate("Enter your name!")  ; Create a new Input
aInpSetActive(inp)                            ; Set the active Input 
aInpSelect(inp)                               ; Select the whole text
aInpSetCharsNumber(inp, 20)                   ; Set maximum chars for th Input
aInpAllowNumPad(inp, True)                    ; Set the Input tu allow NumPad
aInpAllowSelection(inp, True)                 ; Set the Input to allow Selection

Global cblnk = CreateBlinker() ; Create a Blinker
SetBlinker(cblnk, 25, 15)       ; Set the Blinker cadence

Global ascii%

While Not KeyDown(1)
	Cls
	; Draw the moving rectangle
	Color 255, 0, 0
	Rect(x - 20, y -20, 40, 40, True)
	
	; Update the active Text Input
	ascii = aInpUpdate()
	
	; This Part is for drawing the Input result
	; The aInput Library is made to manage but not render to the Screen
	; It also gives all functions needed by the programmer to do those stuffs
	; Use functions like aInpGetText, aInpGetSelPos, aInpGetCursorPos
	DrawInputText()
	;DebugLog(aInpLeftText$(inp) + "/" + aInpGetSelText$(inp) + "/" + aInpRightText$(inp))
	
	; If the Return Key is pressed then modifie the Input Text 
	If ascii = 13 Then
		aInpSetText(inp, "Try again!")
		aInpSetCursorPos(inp, Len(aInpGetText$(inp))) ; Set the cursor to the end
		aInpSetSelPos(inp, 0)                         ; Set the Selection pos to the start
	EndIf
	
	; Move the Background rectangle
	x = x + xinc : y = y + yinc
	If x < 0 Or x > 639 Then xinc = -xinc
	If y < 0 Or y > 479 Then yinc = -yinc
	
	Flip
Wend

Function DrawInputText()
	Local txt$, strw%, strh%, x%, y%, lefttxt$, seltxt$, righttxt$, leftw%, selw%, cpos%
	
	txt$ = aInpGetText$(inp)
	lefttxt$ = aInpLeftText$(inp)
	seltxt$ = aInpGetSelText$(inp)
	righttxt$ = aInpRightText$(inp)
	
	leftw = StringWidth(lefttxt$)
	selw = StringWidth(seltxt$)
	strw = StringWidth(txt$)
	strh = StringHeight(txt$)
	
	cpos = StringWidth(Mid$(txt$, 1, aInpGetCursorPos(inp)))
	
	x = (640 - (strw)) / 2
	y = (480 - (strh)) / 2
	
	Color 255, 255, 255
	Text x, y, lefttxt$
	Color 160, 160, 160
	Rect x + leftw, y, selw, strh
	Color 0, 0, 0
	Text x + leftw, y, seltxt$
	Color 255, 255, 255
	Text x + leftw + selw, y, righttxt$
	
	If Blink(cblnk) Then Rect x + cpos - 1, y, 2, strh
End Function


it does what it says on the tin, the only improvement i can think of is when you keep your finger on delete it deletes more than one letter.

Hi, Chunkations!

I' ve updated the lib with your suggestion and now, you can let the BaskSpace key pressed but also the Del key and so on for Cursor keys...

Here is a new version of the library: See the first post.

The litle demo gives you the ability to select a part of the text by holding the shift key with cursor.

There are few missing functions that I need to implement to make this library very complete.

aInput will let you deal with Text Input in background. This means that the Text drawing part will devolve to the programmer.
It can also be used to enter CheatCodes in a game (without the drawing part, during the game's loop).

Please tell me if it's useful...