How to disable key/character repeat?

Door mcavalcanti

Rookie (20)

afbeelding van mcavalcanti

21-03-2013, 12:32

Hello, guys. Please, is there a way in BASIC to disable key/character repeat? I know in ASM you can control the repeat delay.

Best.

Aangemeld of registreer om reacties te plaatsen

Van anonymous

incognito ergo sum (109)

afbeelding van anonymous

21-03-2013, 17:59

Example with cursor up key:

10 a$=inkey$
20 if stick(0)=1 then gosub 50: goto 40
30 goto 10
40 defusr=&h156: a=usr(0): print "done": end
50 if stick(0)=1 then 50 else return

as long as the key remains pressed, the program remains in line 50.
after release it goes to line 40 where the keyboard buffer gets emptied and the program ends.

Van mcavalcanti

Rookie (20)

afbeelding van mcavalcanti

22-03-2013, 00:01

Thanks, Meits. Worked for me. Easy, huh? Smile
I thought there was a way to do this via poke or something like that.

Best!

Van AuroraMSX

Paragon (1900)

afbeelding van AuroraMSX

22-03-2013, 16:57

Here's a code snippet that should work for any key that has a character code, not just cursor up...

10 a$=inkey$: if a$="" then 10 ' wait for key press
20 if inkey$<>"" then 20       ' wait for key release
30 print a$ " pressed"
40 goto 10

Van mcavalcanti

Rookie (20)

afbeelding van mcavalcanti

26-03-2013, 01:27

Hello, AuroraMSX. This method did not work for me. Key/character repeat remained. Sad

Van anonymous

incognito ergo sum (109)

afbeelding van anonymous

26-03-2013, 14:36

I've been looking around in some old examples from magazines and came up with this:

10 A$=INKEY$: IF A$<>"" THEN GOSUB 30 ELSE 10
20 PRINT A$;" pressed": DEFUSR=&H156: A=USR(0): END
30 B=0: FOR I=0 TO 10: A(I)=PEEK(I+&HFBDA): B=B+A(I): NEXT I: IF B<2805 THEN 30 ELSE RETURN

It scans the keyboard on pressed keys... If a key is pressed B will be < 2805

While brainstorming a bit with Bifi the code got optimized to compare newkey / oldkey

10 A$=INKEY$: IF A$<>"" THEN GOSUB 30 ELSE 10
20 PRINT A$;" pressed": DEFUSR=&H156: A=USR(0): END
30 B=255: FOR I=0 TO 10: B=B AND PEEK (&HFBE5+I): NEXT: IF B<>255 THEN 30 ELSE RETURN

This one is a tad faster and consumes quite a lot less memory than mine. Bifi stated that using arrays in this case is a pity for the memory it consumes. My versions takes 131 bytes and Bifi's version takes 35 bytes... If you can live with that, this could be a way...

Van mcavalcanti

Rookie (20)

afbeelding van mcavalcanti

26-03-2013, 15:39

I found a method written by Imanok in 2011. In this case, to avoid space bar repeating:

10 IF STRIG(0)=0 THEN SP=0 ELSE IF SP=0 THEN SP=1:PRINT"SPACE PRESSED"
20 GOTO 10

And I used your (Meits) method for cursor keys. Smile

My MSX profile