It only runs until the first key is pressed and then stops
That's exactly what your loop says: "while no key has been pressed, keep looping" (i.e., stop as soon as a key is pressed).

Presumably you want something more like:
Code:
    while (true) {
        if (kbhit()) {
            // handle keyboard stuff
        }
        else if (mousehit()) {
            // handle moust stuff
        }
    }
If "mousehit" (or something similar) doesn't exist then you need to write it. A quick google suggests it would use int86().

But it's still a suboptimal method. We would usually let the program sleep until something happens instead of using an active loop.