Page 1 of 1
Read keypress status of multiple keys on CX16?
Posted: Mon Jul 24, 2023 7:57 pm
by mwiedmann
Is there a way to read the keypress status of multiple keys on the CX16? I need to read the status of multiple keys at the same time. Meaning for instance, I want to know if they are pressing W, E, and R. Or know that they are NOT pressing R.
The kernal functions seem to use a buffer.
Re: Read keypress status of multiple keys on CX16?
Posted: Tue Jul 25, 2023 6:23 am
by kelli217
It’s possible to communicate directly with the SMC, and poll the keyboard yourself instead of it being done by the kernal interrupt handler.
Re: Read keypress status of multiple keys on CX16?
Posted: Tue Jul 25, 2023 6:26 pm
by Daedalus
You can, but it's not simple. The docs for it are on the github under "Editor", the section you want is near the end and is called "Custom Keyboard Keynum Code Handler"
First, if you're using the emulator, you need to be using r43.
Then you need to be running a custom interrupt handler. Then you hook into the scan code hook at #32e/$32f (This is all in the docs, along with a sample keyboard handler to get you started.)
Note that to do what you want, you need to set a state for all the keys you want tracked independently of the keyboard based on their scan codes (What the PS/2 keyboards sends to identify each key.) When a "key down" code comes in, set the state as down, then when the "key up" code comes in, set it as released. Once that is running, your game uses that array of states to know if a key (Or many keys) are pressed at any one time.
A detail to understand is that the "key repeat" comes from the PS/2 keyboard itself, in the scan codes, not from the KERNAL. So you can receive many "key down" events on a key if it's being held down, and only one "key up" event when it's released.