Author Topic: Odd multiple input problem  (Read 4982 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Odd multiple input problem
« Reply #15 on: July 13, 2019, 11:57:21 am »
Hi guys
I think that this is a good solution... only if someone let me see where I must put _KEYCLEAR to void the buffer's tail :-((

Code: QB64: [Select]
  1. CONST left = 1, right = 2, up = 3, down = 4, fire = 5, true = -1
  2. DIM arrow(1 TO 10) AS INTEGER, comm AS LONG, comms(1 TO 10) AS STRING
  3. arrow(left) = 19200
  4. arrow(right) = 19712
  5. arrow(up) = 18432
  6. arrow(down) = 20480
  7. COLOR 11, 2
  8.  
  9. PRINT (arrow(left)), (arrow(right)), (arrow(up)), (arrow(down))
  10.     CLS
  11.     comm = _KEYHIT ' memorize hardware input
  12.  
  13.     ' inizialize engine flag
  14.     IF comm > 0 THEN
  15.         ' key is pressed
  16.         IF (comm) = ((arrow(left))) THEN
  17.             comms(left) = STR$(true)
  18.         ELSEIF (comm) = ((arrow(right))) THEN
  19.             comms(right) = STR$(true)
  20.         ELSEIF (comm) = ((arrow(up))) THEN
  21.             comms(up) = STR$(true)
  22.         ELSEIF (comm) = ((arrow(down))) THEN
  23.             comms(down) = STR$(true)
  24.         END IF
  25.     ELSEIF comm < 0 THEN
  26.         ' key is released
  27.         IF (comm) = -((arrow(left))) THEN
  28.             comms(left) = ""
  29.         ELSEIF (comm) = -((arrow(right))) THEN
  30.             comms(right) = ""
  31.         ELSEIF (comm) = -((arrow(up))) THEN
  32.             comms(up) = ""
  33.         ELSEIF (comm) = -((arrow(down))) THEN
  34.             comms(down) = ""
  35.         END IF
  36.     END IF
  37.  
  38.  
  39.     ' engine
  40.     throw.x = 0
  41.     LOCATE 3, 1: PRINT "Xmove=";
  42.     IF VAL(comms(left)) = true THEN throw.x = -1: PRINT " Left   "
  43.     IF VAL(comms(right)) = true THEN throw.x = 1: PRINT " Right "
  44.  
  45.     throw.y = 0
  46.     LOCATE 5, 1: PRINT "Ymove=";
  47.     IF VAL(comms(up)) = true THEN throw.y = -1: PRINT " UP    "
  48.     IF VAL(comms(down)) = true THEN throw.y = 1: PRINT " Down "
  49.     IF throw.x = 0 AND throw.y = 0 THEN throw.x = 1
  50.  
  51.     IF comm = (32) AND spacepress = false THEN
  52.         spacepress = true
  53.         LOCATE 1, 1: PRINT "Spacepress="; spacepress; "  "
  54.         '     CALL spawn_shot(0, throw.x, throw.y)
  55.     ELSE
  56.         spacepress = false
  57.     END IF
  58.     IF comm = (27) THEN END
  59.     ' _KEYCLEAR
  60.     LOCATE 1, 1: PRINT "Spacepress="; spacepress; "   "
  61.     _LIMIT 10
  62.  
  63.  
Programming isn't difficult, only it's  consuming time and coffee

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Odd multiple input problem
« Reply #16 on: July 13, 2019, 01:43:46 pm »
Yes, the buffer is a huge problem when running the code. You can retrieve a single key entry by using _KEYCLEAR immediately after:    comm = _KEYHIT ' memorize hardware input

I'm surprised this worked for you, because on my system, it will not detect more than 2 keys when I use left arrow + up arrow + spacebar. Now some other combos work, but the one mentioned left arrow + up arrow + spacebar needs to work to have a breakthrough. I wish I could remember a way to get PEEK to recognize a spacebar press. In my attempt, I had to substitute Shift for the spacebar, so I really can't say if a way to PEEK a spacebar press would work or not. It just isn't apples to apples... more like Apples to Windows. Anyway, only certain PEEK/POKE are still preserved, as this was all 16-bit stuff, back in the day. I did find that PEEK(197) worked to find a key press on a Commador64, but that lower rage is apparently ignored on non-16 bit systems. Oh well, that's "progress" for you!

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Odd multiple input problem
« Reply #17 on: July 14, 2019, 01:18:05 pm »
Hi Pete
about _KEYCLEAR
it doesn't solve the problem of the buffer

if I put it just after _KEYHIT I got a strange effect ON OFF for the key pressed without any detection if the key has hold or no.
If I put _KEYCLEAR in the area of waiting for new cycle after _LIMIT 10 and/or before _KEYHIT the program doesn't catch input from keyboard.
.....

about my workaround I have tested it using an USB keyboard and it can catch only 2 arrow keys and no more plus!
Also _KEYHIT seems to soffer of Hardware limitations.
In this case I think that also using PEEK  or INP there is no matter to do. Where the hardware fails there is not possible to use so combo! So for using  professional games with combo using plus 2 keys , the user must use a gamer keyboard with no limit (like PS/2 as said in the article linked by Steve).

Well at my home, if I want develop a game with such kind of combo (more than 2 keys) I must use one of the 2 notebook TOSHIBA that with their inner keyboard let me catch all the keys I like to catch. But if I use an USB keyboard (I have tested 2 keyboards USB and wireless made by different manufacter [Sigma, Trust]) I fall in the hardware issue.
While the 2 HP notebook  show the hardware issue also with their inner keyboard. 

Thank for reply Pete

In sum: the solution is  use a power hardware for gaming  or write a game with no such kind of combos.
Programming isn't difficult, only it's  consuming time and coffee