1
1
Fork 0
mirror of https://github.com/QB64Official/qb64.git synced 2024-07-03 07:41:21 +00:00

Added a _KEYCLEAR [buffer&] command to clear any characters in input buffers.

Without a parameter, it clears all buffers. A numeric parameter will
clear only a specific buffer: 1 = INKEY$ buffer (and other traditional
QB input commands), 2 = _KEYHIT buffer, 3 = INP(&H60) buffer. The last
one is not actually cleared, but we pretend we've read all the data from
it.

To ensure no stray characters, use this command immediately before the
code you wish to sanitise. You never know when the user might bang on
the keyboard, and this also helps to avoid stray key release values
persisting in the _KEYHIT buffer.
This commit is contained in:
Luke Ceddia 2014-09-27 03:12:54 +10:00
parent c100a8b8b9
commit 801ae6ae60
3 changed files with 29 additions and 0 deletions

View file

@ -51,3 +51,22 @@ qbs *func__cwd(){
return final;
}
void sub__keyclear(int32 buf, int32 passed) {
if (new_error) return;
if (passed && (buf > 3 || buf < 1)) error(5);
// Sleep(10);
if ((buf == 1 && passed) || !passed) {
//INKEY$ buffer
cmem[0x41a]=30; cmem[0x41b]=0; //head
cmem[0x41c]=30; cmem[0x41d]=0; //tail
}
if ((buf == 2 && passed) || !passed) {
//_KEYHIT buffer
keyhit_nextfree = 0;
keyhit_next = 0;
}
if ((buf == 3 && passed) || !passed) {
//INP(&H60) buffer
port60h_events = 0;
}
}

View file

@ -3,3 +3,4 @@
* Write me at <flukiluke@gmail.com> if I broke something
*/
qbs *func__cwd();
void sub__keyclear(int32 buf, int32 passed);

View file

@ -5,4 +5,13 @@ id.musthave = "$"
id.subfunc = 1
id.callname = "func__cwd"
id.ret = STRINGTYPE - ISPOINTER
regid
clearid
id.n = "_KEYCLEAR"
id.subfunc = 2
id.args = 1
id.arg = MKL$(LONGTYPE - ISPOINTER)
id.specialformat = "[?]"
id.callname = "sub__keyclear"
regid