2

I am building a Mortal Kombat game in assembly as an final project. I have problems input keys from 2 users without delay or other crappy things.

I have already tried to use the buffer. However, in the game you need to hold the 'd' button for letting one player move right and in the same time hold the left arrow button to let second player move left. I need to find a way to know if a button is pressed or a button is under hold and to know combination of those two options together.

I need for example let first player move right(by holding the key d) and in the same frames let second player move left(by holding the key left arrow) and jumping(by pressing once at upper arrow key)

  • 3
    Depends on the platform is this DOS on x86? – Michael Petch Feb 18 '19 at 08:16
  • 1
    Also note that different keyboards work differently. Some may properly keep track of which keys are held down and which aren't and report the down and up events correctly, while others may fail to report certain (or most, except the common ones) key combinations. – Alexey Frunze Feb 18 '19 at 10:54
  • 1
    For x86 real mode (e.g. DOS) see [my answer](https://stackoverflow.com/a/10525397/968261) to a different question. – Alexey Frunze Feb 18 '19 at 11:01
  • Note that PS/2 keyboard cannot tell you if you pressed keys down at the same time. It always sends you a message to the effect of “you pressed down this key, then that key.” You can however detect if two keys are depressed at the same time by keeping track of key-press as well as key-release events. Quantisise that by frame and you have basically what you want. – fuz Feb 18 '19 at 12:18
  • If this is for DoS/x86 another answer that applies is: https://stackoverflow.com/a/37033680/3857942 – Michael Petch Feb 18 '19 at 12:27
  • When writing the handling for key-up / key-down events, make sure it's robust enough to recover if events are missed. e.g. if you see down/up events for a key that was already down, make sure you treat it as whatever the last event was. (So the user can recover by pressing / releasing keys if the program thinks they were stuck down, e.g. their keyboard cable is loose and came unplugged while a key was down, so the up event was never sent.) – Peter Cordes Feb 18 '19 at 13:33

0 Answers0