SyntaxBomb - Indie Coders

Languages & Coding => Blitz2D, BlitzPlus, Blitz3D => Topic started by: Mikey on December 02, 2018, 03:58:39

Title: Key Bounces
Post by: Mikey on December 02, 2018, 03:58:39
*** Delete This thread. I found the answer ***
Title: Re: Key Bounces
Post by: Steve Elliott on December 02, 2018, 13:53:24
So you had a problem that others might also have, and you've found the solution.  Now you want to keep the solution to yourself?   :P
Title: Key Bounces
Post by: Mikey on December 02, 2018, 22:06:38
NO,

I did not want to take up server space. I can post the source again if you want.
Title: Re: Key Bounces
Post by: Steve Elliott on December 02, 2018, 22:42:45
Anything that could possible help the community could never be called a waste of server space.   :)
Title: Key Bounces
Post by: Mikey on December 02, 2018, 23:14:09
I understand.
Some sites do complain.

Here is the original source. The problem is that the machine is so fast that it does not increment one at a time. It goes from the first to the last, instantly.


While Not KeyDown(1)
If KeyDown(208) And STLI<(NF-(ENDL-1))
STLI=STLI+1:Cls:Gosub PL:;ENDL=ENDL+1:
ElseIf KeyDown(200) And STLI>1
STLI=STLI-1:Cls:Gosub PL:;ENDL=ENDL-1
EndIf
For Z=1 To 10:Text 200,13*(Z-1),T$(Z):Next:;WaitKey:End

Text 150,0,STLI;VWait

Wend
End
Title: Re: Key Bounces
Post by: Qube on December 02, 2018, 23:54:47
QuoteI did not want to take up server space.... Some sites do complain.
Don't worry about that. If the SSD gets full I'll just buy a bigger SSD ;D - Keep posting :)
Title: Key Bounces
Post by: Mikey on December 03, 2018, 00:11:30
Yes, but at some point the cost has to be ridiculous and then where would the information go?
Title: Re: Key Bounces
Post by: Qube on December 03, 2018, 00:12:20
Quote from: Mikey on December 03, 2018, 00:11:30
Yes, but at some point the cost has to be ridiculous and then where would the information go?
An even bigger drive :P
Title: Key Bounces
Post by: Mikey on December 03, 2018, 01:42:32
It will bankrupt you in the very long run.
Title: Re: Key Bounces
Post by: Derron on December 03, 2018, 07:08:29
Every byte counts !!!11!!!!!1

Once Mikey posted his 1.000.000.000 post he will occupy ~ 1kb * 1.000.000.000 = ~100 gigabytes on your SSD. Assume he does not "bot-post" but manual post and needs about a minute to write some stuff then he will have filled your SSD/hard drive in just about 695.000 days. I assume when this moment comes, 100 gigabytes of space won't cost uhm "that much" ;-)


@ keydown
The problem is that "keydown" is emitted as soon as a key is "kept down" and the code handling the OS events is run. So on your fast computer it runs runs runs runs runs ... and always it sees "key is down -> keydown becomes true".

Solution is to have some kind of "keyHit" (becomes "true" once it _was_ keydown but now is _no_longer_ keydown). Or you add your own "KeyPress()". Means you store when KeyDown/KeyHit/... events for a special key happen. Then add your own timing code (eg. you can only "keyPress" once every X milliseconds). This also allows for "repeat key strokes"). You while the user keeps pressing a key ("keyDown=true everytime") you store a "keyDownTime = Millisecs()" thing as soon as "keyDownTime - lastKeyDownTime > xxx". If you update "lastKeyDownTime" then to the current time it will emit it next time once "xxx" time has passed. This allows then to keep it pressed but only emit a "keystroke" every xxx time.


bye
Ron
Title: Key Bounces
Post by: Mikey on December 03, 2018, 22:05:40
This was the solution that I used:

While Not KeyDown(1)
CH=GetKey()
If CH<>0
If KeyDown(208) And STLI<(NF-(ENDL-1))
STLI=STLI+1:Cls:Gosub PL:;ENDL=ENDL+1:
ElseIf KeyDown(200) And STLI>1
STLI=STLI-1:Cls:Gosub PL:;ENDL=ENDL-1
EndIf
For Z=1 To 10:Text 200,13*(Z-1),T$(Z):Next:;WaitKey:End

EndIf
Wend


It does not emit a repeating key press if the key is held down though