Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 19th Apr 2012 16:34
Hello Ya'all:

Does anyone know how to clear the value of inkey$?

Lance
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 19th Apr 2012 17:34
the value of inkey$ is cleared as soon as you release the keyboard.

ShaunRW
DBPro Developer
18
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 19th Apr 2012 17:50
Entry$ is the one that needs to be cleared. And that is by calling Clear Entry Buffer.

Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 19th Apr 2012 21:38
Hello basjak:

No it isn't - it keeps indicating the same value until something else is pressed.

Hello ShaunRW:

Thanks - that works as a great alternative...

Lance
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 19th Apr 2012 21:45
Hello ShaunRW:

Not so fast - entry$ isn't picking up every key. It doesn't recognize arrow keys, for example.

Lance
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 19th Apr 2012 21:49
Hello basjak:

You did give me an idea: I can use inkey$, and only wait for the input to change before reading it. So for example, one key is hit, then the program waits until another is hit. This has the drawback of disabling a keyboard repeat, but that's OK in my case.

Lance
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Apr 2012 22:59
No, inkey$ only shows the currently pressed key. As soon as you release the key it is reset.

If you are getting something else, show us the code you are using, and we'll show you where the bug is

Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 19th Apr 2012 23:10
inkey$ is a crap command anyway. Anything to do with detecting button presses should be done with keystate(), as inkey$() has 2 major issues 1) it only supports 1 key at a time 2) it's tied to your framerate, if you press and release/change keys between each frame/loop it won't be recognised

keystate() suffers from problem #2 but not #1. Irrelevant for most button actions, typing however is a problem so this is where entry$() comes in. It's a buffer that fills up until it's called by your program, so you can mash away at the keyboard as fast as you want and each keystroke is recorded. Either append it to a string, or read it character by character
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 19th Apr 2012 23:25
My open source TopGui project has example code for how to capture every key press reliably using IanM's plugins.

[b]
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 20th Apr 2012 21:47
Hello Diggsey:

Ah, yes, TopGui - I looked at that code before:

"Could not understand command at line 176."

Lance
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 20th Apr 2012 21:58
As far as a code sample goes for inkey$, how about:

while 1
a$=inkey$()
print a$;
endwhile

Output, when pressing and releasing the "k" key:

kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk

In other forms of basic, such as GW Basic of QBasic, you could put a poke statement right after the a$=inkey$() statement, and if you pressed k, you would get only one "k". If you held down the k-key, then after the BIOS-set keyboard repeat delay, then it would start to repeat. What is happening in DBP is it is reading the key witout resetting. ShaunRW's code works, but the problem there is it apparently only reads alpha and numeric keys - not other keys. So what I think I have to do with inkey$ is write a couple more lines of code, so that if they key is returning the same code, to ignore it (in my application, I don't want the key to repeat at all). In fact, here it goes:

o$="11"
while 1
a$=inkey$()
if o$<>a$ then print a$;
o$=a$
endwhile

- It works, and I credit both basjak and ShaunRW for the fix. Currently, I was using keystate, but found that I had to induce a delay to make it work properly (i.e. my loop was so fast). basjak taught me that eventually, the key does stop, ShaunRW had a good/working idea, but it just didn't work for my application. So hats off to all of you...
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 21st Apr 2012 05:58
sorry, I was very busy to comeback to this thread.

glad you got the problem sorted.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Apr 2012 15:09
@ Statue

The reason why a$ seems not to change until you press another key has nothing to do with inkey$(), but with the fact that your screen stores the data you print to it.

Your updated example is a waste of processing power and just not needed. Here's an example showing the first code you posted but with the screen set up correctly:



You'll see that inkey$() is working just as everyone else has been describing it.

I recommend not using inkey$(), but the command keystate() for things like control.

If you want to get the arrow keys, there are already dedicated commands for that : upkey(), downkey(), leftkey(), rightkey().

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Apr 2012 15:37
@TheComet
I think you've missed his point. Your code will keep recording the last value pressed - and you could get many dozens of "hits" till the user releases the key. That would be very annoying if you were trying to type a word as in the following variation of your snippet:



Try typing any word and see what happens.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Apr 2012 20:13 Edited at: 21st Apr 2012 20:14
Ah well in that case I'd use entry$(). I thought he was trying to use it for controls such as WASD. Here's my get_entry() function ripped from my standard text input source file:



What's also interesting with the code above is when you set the sync rate to something really low, say 5. It is still able to capture everything.

TheComet

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Apr 2012 23:39
Quote: ""Could not understand command at line 176.""


Yes, as I said you need IanM's plugins.

[b]

Login to post a reply

Server time is: 2026-07-09 00:07:08
Your offset time is: 2026-07-09 00:07:08