Nice one, I was trying with @chr(getkey()) with no result :)dodicat wrote:Another possible method to clear the keyboard buffer.Code: Select all
dim as function() as string clearbuffer=@inkey() print "Press a key to continue .." sleep clearbuffer() print "len inkey = ";len(inkey) print "Press a key to end .." sleep
How to reset the value when using input
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: How to reset the value when using input
Re: How to reset the value when using input
@dodicat
:-)
But I prefer that following version:
:-)
But I prefer that following version:
Code: Select all
#macro clearbuffer()
While Inkey <> ""
Wend
#endmacro
print "Press a key to continue .."
sleep
clearbuffer()
print "len inkey = ";len(inkey)
print "Press a key to end .."
sleep
Re: How to reset the value when using input
That way is standard (I think because of habit more than reason IMO)
But inkey clears the buffer itself by definition anyway.
...
Peeks into the keyboard buffer and returns a String representation of the first character, if any, found. The key is then removed from the buffer ..
But inkey clears the buffer itself by definition anyway.
...
Peeks into the keyboard buffer and returns a String representation of the first character, if any, found. The key is then removed from the buffer ..
Code: Select all
print "Press a key to continue .."
sleep:inkey
print "len inkey = ";len(inkey)
print "Press a key to end .."
sleep
Re: How to reset the value when using input
fxm wrote:'While InKey <> "" : Wend' instead of a simple 'InKey', is a security against eventual multi key-pressed during the waiting if the CPU is hogged.
Re: How to reset the value when using input
Another method(windows)
Linux is read I think
Linux is read I think
Code: Select all
#macro clearbuffer()
While Inkey <> ""
Wend
#endmacro
#define emptybuffer shell("pause >nul")
print "Press a few keys (you have five seconds) .."
sleep 5000,1
print "Now press a key to continue . . ."
emptybuffer
print "len inkey = ";len(inkey)
print "Press a key to end .."
sleep
Re: How to reset the value when using input
Right, as long as I do not have enough positive echoes, I do not touch the SLEEP documentation page.MrSwiss wrote:Leave it, as is ... (aka: no need for change)
Reason: the only person here, that has mastered the Art of complexifying everything,
instead of keeping simple things the way they are, should not be the "yardstick" ...
(do nothing, everyone can do it!)
(me it does not bother me, I know how it works!)
But the next time a user is caught by this behavior, I will complement the explanation in the SLEEP documentation (as suggested above).
Last edited by fxm on Feb 22, 2019 9:42, edited 2 times in total.
Re: How to reset the value when using input
The inkey page needs fixing for the coming version 1.06
They are all inkey$ at the moment.
(I cannot do it, I am not on the long list).
My swansong here, clearbuffer+
They are all inkey$ at the moment.
(I cannot do it, I am not on the long list).
My swansong here, clearbuffer+
Code: Select all
function clearbuffer() as string
dim as string tot,char=chr(0)
while char<>""
char=inkey
tot+=char
wend
return tot
end function
print "Press a few keys (you have five seconds) .."
sleep 5000,1
print "Now press a key to continue . . ."
var contents=clearbuffer
sleep
clearbuffer
print "Buffer contained ";contents
print "len inkey = ";len(inkey)
print "Press a key to end .."
sleep
Re: How to reset the value when using input
Already done, and also for other relevant keywords.dodicat wrote:The inkey page needs fixing for the coming version 1.06
They are all inkey$ at the moment.
See paragraph "Dialect Differences" at pages:
Chr[$], Command[$], Hex[$], Inkey[$], Lcase[$], Left[$], Ltrim[$], Mid[$] (statement), Mkd[$], Mki[$], Mkl[$], Mks[$], Oct[$], Right[$], Rtrim[$], Space[$], Str[$], String[$] (function), Trim[$], Ucase[$].