My solution to this scale thing was a little more elaborate. What I wanted was something that included all transpositions of the major scale, but also melodic minor, harmonic major, harmonic minor and two subsets of the diminished scale. These are all the 7 note scales you can get from 12TET that don't have two adjacent semitone intervals. Since major scales are connected in a circle of fifths arrangement, I thought about how the other scales related to each other. This turns out to be exactly what Dmitry Tymoczko wrote about in his "Scale Networks and Debussy" paper.
To implement this, two states are stored: both the scale number (0 to 5) and the transposition (0 to 11). To change scales, I actually use 4 lists of numbers that are loaded from text files and stored in tables. The lists include the number to search for to change to the next scale, the number to add to that to change it, the new scale, and the transposition to the next scale. I increment the scale by the complement of its transposition (to transpose it back to a standard form), locate the "search number", increment it by the "increment number", then set the scale to the new scale, increment the transposition, then re-transpose the scale. This takes care of all the different transpositions of the scale, without having to store them.
I know that description is completely confusing and unreadable. The code is a mess too, and is impossible to read or troubleshoot. BUT this enables me to use some Octave scripts to generate these lists of numbers. So I can take any arbitrary temperament, look for the most consonant scales, find the relationships between them, and write the output to these text files. If I load different text files, I can easily use a completely different temperament.
Anyway I thought [key] and [keyname] were standard Pd objects... look in the help browser in manuals/0.Intro/48.grabbing_keystrokes.pd