Smart Keys

Published 2023-06-12


[8x8]

Since copyright was a concern earlier, I would like to state that this code and any other code I have or may produce in the future is licensed for use only under PICO-8. That is, my code is free for anyone and everyone to use entirely as they like for whatever freeware project they have in mind, yet its use is to remain strictly in this programming language PICO-8, and no other languages or derivations are allowed unless permission otherwise is granted from the author.

One other stipulation, if you use my work in a commercial setting or it is a project of more than one person, I must be able to see "dw817" somewhere in it. No-one ELSE needs to see it, but I do. So stuff it sideways or backwards in your 1-second logo, whatever. a reminder to let me know I helped someone else fulfill their project dream.

You can see this copyright and license in usage by the inclusion of the icon above in the SPRITES tab - and you are welcome to use it also for your own packages to denote the self-same copyright and license restrictions and allowances.

UPDATES

WHAT'S NEW ??

09-25-18

09-24-18

09-23-18

So what exactly is this ?

It's a comprehensive function you can call to return the standard 6-keystrokes in many different ways.

If you set KEYTYPE to zero, you have true arcade controls. No staggering for any input, multiple keystrokes can be read via KEYIN("zz") where "zz" is the name of the key you want to see if it appears in that particular stroke.

Possible keys are "L" "R" "U" "D" "A" and "B" and can be returned singly or if multiple keys are held.

You can press any number of these keys including holding down the LEFT or RIGHT arrow key and the "O" button. No need to stop pressing one to register another. KEYIN() can return all 6-keystrokes simultaneously if need be.

You can also press UP and DOWN to return "UD" special keystroke.
Press LEFT and RIGHT to return "LR" special keystroke.
And press "O" and "X" (Z and X) to return "AB" special keystroke.

These 3-keystrokes will appear only once in a strobe and and then return no more keystrokes until you release them.

If you want regular input like for menus and selections where all keystrokes are staggered by delays and time held, change KEYTYPE to 1 (one).

Now diagonal movements flip between two keys if both are held. (A) and (B) register once, pause, again, pause, then repeat.

You truly get just one keystroke outside of the 3-special listed above. You can also change the default counting delay of 8 to anything you want. Change global "KEYTIME" shown at the beginning of _INIT()

The KEYTYPE #2 is a very special case indeed. You still have diagonal movements flip between two keys but now (A) and (B) only register when RELEASED. If you hold either down for a short while, you get a new special keystroke called either "A+" or "B+" depending upon which you held.

Continue to hold that key down and you can still navigate with the arrow keys. But if at any point you release (A) or (B), whichever was held, a new keystroke is sent of "A-" or "B-" signifying you have released it, and you can also register that comparison directly in your code.

That's it !

I hope you find this function instrumental and useful in your existing and future carts. I certainly plan to make use of it myself. Thank you for your time !