TO LOAD THIS PICO-8 CART, in immediate mode, type:
I was unaware that Pico-8 could read raw keystrokes. While we have the ability of reading normal keystrokes, I have not seen any code from others that will register reading and determining whether or not you pressed the LEFT shift key or the RIGHT one.
This program will do just that, in addition to a whole host of other keys - that you really shouldn't press as they could be associated with a function. Yet this program does correctly read function keys for instance, F1-F12. It reads if you pressed CAPS-LOCK, NUMBER-LOCK, SCROLL-LOCK, left CTRL, right CTRL, and every other key on the keyboard.
Run the code and press the key you are interested in. A short code sample will appear below on how to read that particular key.
Tap SPACEBAR to change from showing the keystroke to showing the actual SCANCODE.
The table to this can be found HERE:
Look at the source-code and see where the scissors are cutting. Copy that to your code for true raw-key reading and you are all set.
If you are using a non-IBM keyboard, you can add to the codes with 6-characters.
The first 3-characters represent the decimal of that raw scancode. If it is 1-digit long then add 2-zeroes in front. If it is 2-digits long, add 1-zero in front. If it is 3-digits long, then do not add any zeroes in front.
The next 3-characters is the name you want to call that scancode.
If for instance you wanted to name it, "@" then it would be "@" followed by 2-spaces. Always pad the name to 3-characters. The additional spaces are always truncated in creation of the arrays KEYS and KEYN.
For instance, to read you holding down all =3= of these keys "Q" "W" and "E" the code would be:
if stat(28,keyn["q"]) and stat(28,keyn["w"]) and stat(28,keyn["e"]) then ...
You could also use the direct scancodes which this program also provides.
if stat(28,20) and stat(28,26) and stat(28,8) then ...
Mix and match, build your own keyboard driver with your custom repeat delays and speeds.
Now if you want "P" to be read and not just go straight to the menu, include this code at the top or bottom of your _update() function.
Be aware if you HOLD down the "P" key the pause will eventually appear and at this time there is no way to bypass that.
Also you may get different keystrokes in running immediate mode and Online. For instance for me I use the arrows on the number keypad to navigate games. Online it registers as the real arrow keys. Offline they register as the number keypad.I am including ^^ this small cart to read ANY keystroke coming back. It should work for all keyboards including Macintosh and all 8 joysticks including the START button.
If you have any questions or comments about this program and its functions, please let me know !
[Please log in to post a comment]