Disable 'key' object when in edit mode?
I use the 'key' object to create keyboard shortcuts on almost every key on my laptop. Very handy for performance, but obviously it can be irritating when I'm in editing mode, and all those keys start accidentally triggering things as I type. Is there any easy solution to this problem?
I thought about sending the key output through a gate, which I could then turn off with (yet another) keyboard command when I start editing. But I'd have to remember to do that every time I go into edit mode, and besides it's a pain. (Also, I couldn't use a key command to re-enable key when I'm done editing!)
Thanks! I really need to learn javascript at some point, ha.
At any rate, I'd need to install the code in each subpatch, right?
It is meant to sit behind the key object. In this form it only checks if the patcher containing the js is locked. But it could probably be modified to walk the patcher tree and look for any unlocked patcher.
Thanks so much for this! Looking forward to trying it out!
If like me, you've landed here because you want to poll the locked/edit state of your patcher, here's a more complete version that polls the state every 500ms and only returns a value if the state changes. Activated with a toggle.
lockedState = 0;
// Outputs only if state changes
function isLocked() {
if (this.patcher.locked) {
if (lockedState == 0) {
lockedState = 1;
outlet(0, 1);
}
} else {
if (lockedState == 1) {
lockedState = 0;
outlet(0, 0);
}
}
// Otherwise don't return anything, no change in state
}
t = new Task(isLocked, this);
t.interval = 500; // Locked state polling interval
// Run only if activated
function msg_int(val) {
if (val === 0) {
t.cancel();
} else {
t.repeat();
}
}
you can ask [thispatcher] for "locked".
Aw thanks Roman I didn't know that!
In case anyone wonders, you can get the lock state with a [getattr locked] connected to [thispatcher]. Maybe I'm missing the correct syntax to get it from a message?
getattr is what i meant, but i just tried it in max 8.1.x and there it does not yet work? (invalid attribute) only in max 9?
i´ve always thought that this is the difference between "locked 1" and "lockdown", that one is an attribute. i see no other differences between these two messages...
to make sure i tested getting all attributes too, but to no avail. does that work in max 9?

I can confirm this doesn't work for me in Max 8.6.5 but does in 9.0.8.
I wasn't aware of lockdown
either, which seems to set the patch in a permanently locked state that cannot be unlocked.