To do it properly, you can't use Input as whatever the user types is passed as a whole entity only when the Enter key is pressed.
Using Inkey$(), Entry$() or ScanCode() on the other hand, you can read in characters one at a time and filter out the non-numeric characters you don't want.
But, you also have to process manually all the other keypresses you need - like the Enter, backspace and cursor keys. But, on the plus side, you can make yourself a cursor which you don't normally get.
Here's the basic version of a number input function I wrote a while back and then modified for Dark Sprites:
Set Text Opaque: Rem <<< Required before calling function (can be set back to transparent after if required)
Entered$ = InputNum("30",100,100,100,16,999)
CLS
Print "You Entered The String: ";Entered$
Print "Which As A Number Is: ";VAL(Entered$)
Wait Key
End
Function InputNum(Proj$,TextPosX,TextPosY,BoxWid,BoxHig,MaxNum)
LenText = Len(Proj$)
CurPos = LenText+1
ExitTextFunc = 0
Ink 0,0: Box TextPosX,TextPosY,TextPosX+BoxWid,TextPosY+BoxHig: Rem Colour Of Screen Behind Text
Ink RGB(255,255,255),0: Rem Colour Of Text
Repeat
Char$ = entry$()
Select ASC(char$)
Case 0
Rem No ASC Key - Check For Cursor Keys
If LeftKey()=1
Dec CurPos
If CurPos < 1 Then CurPos=1
If CurPos > LenText
Before$ = Proj$
After$ = ""
Text TextPosX+1,TextPosY,Before$+"|"+After$
Else
Before$ = Left$(Proj$,CurPos-1)
After$ = Right$(Proj$,LenText-CurPos+1)
Text TextPosX+1,TextPosY,Before$+"|"+After$
Endif
Repeat
Until LeftKey()=0
Endif
If RightKey()=1
If CurPos<LenText+1 Then Inc CurPos
If CurPos > LenText
Before$ = Proj$
After$ = ""
Text TextPosX+1,TextPosY,Before$+"|"+After$
Else
Before$ = Left$(Proj$,CurPos-1)
After$ = Right$(Proj$,LenText-CurPos+1)
Text TextPosX+1,TextPosY,Before$+"|"+After$
Endif
Repeat
Until RightKey()=0
Endif
Endcase
Case 8 : Rem Backspace
Before$ = left$(Before$, len(Before$) - 1)
Proj$ = Before$+After$
Dec CurPos: If CurPos < 1 Then CurPos=1
LenText = Len(Proj$)
If Proj$ = ""
Before$="": After$=""
Endif
Ink 0,0: Box TextPosX,TextPosY,TextPosX+BoxWid,TextPosY+BoxHig: Rem Colour Of Screen Behind Text
Ink RGB(255,255,255),0: Rem Colour Of Text
Endcase
Case 13 : `Carriage return
ExitTextFunc = 1
Endcase
Case Default
If ASC(Char$)>47 And ASC(Char$)<58
Rem Filter Out All But Numbers 0..9
If MaxNum = -1
Rem Max Num Available In Box
If Text Width(Proj$) < BoxWid-8
Proj$ = Before$ + Char$ + After$
Inc CurPos
LenText = Len(Proj$)
Endif
Else
Rem Supplied Max Num
TNum = VAL(Proj$+Char$): Rem Get value of num after char$ is added
If TNum > MaxNum
Proj$ = Str$(MaxNum)
Inc CurPos
LenText = Len(Proj$)
Else
Proj$ = Before$ + Char$ + After$
Inc CurPos
LenText = Len(Proj$)
Endif
Endif
Endif
Endcase
Endselect
Clear Entry Buffer
Rem Display the text
If CurPos > LenText
Before$ = Proj$
After$ = ""
Text TextPosX+1,TextPosY,Before$+"|"+After$
Else
Before$ = Left$(Proj$,CurPos-1)
After$ = Right$(Proj$,LenText-CurPos+1)
Text TextPosX+1,TextPosY,Before$+"|"+After$
Endif
Sync
Until MouseClick()<>0 Or ExitTextFunc = 1
EndFunction Proj$
Notes On Using The Function:
1. The function returns a string. Use VAL() to convert it if you need it in a proper numeric variable.
2. The first parameter allows you to pass a 'current' or 'default' value to the function. The above example uses "30" so that is what appears by default and the user can edit it or just press Enter to use it.
3. Parameters 2 and 3 are the screen X and Y position you want the input box to appear. (The function was designed to work on a non-black screen, so if required the RGB values can be altered in the function).
4. Parameters 4 and 5 are the width and height of the text box. If you look at Dark Sprites, you will see how they are used, but you may not have a use for these parameters.
5. The last parameter is a maxvalue value where you can stipulate the maximum number the user can type in. If the number they type in exceeds this value, what they typed will be replaced with the value you enter for this parameter.
Hope it's of some use for you. If it is, by way of a thank you, please promise to never use Goto again!!
TDK