Select Number

Coming from Isadora (where its quite intuitive) there is a quite simple thing i try to achieve, but just dont get to it.
For exemple I want to send a specific numbers to a constantCHOP by pressing different keyboard keys. So lets say I press “a” on the keyboard, then the constant should have the value “1”. When I press “b” the same constantCHOP should change from “1” to “3”. I tried with logicCHOP, the mathCHOP and the merge"CHOP", but nothng works, so that the ConstantCHOP gets the value of the last sent number. How could I do this?

I did a fair bit of izzy work years ago now, and while this seems like it aught to be straightforward, it’s a little harder to nail down in practice. I think the most direct solution is to handle this with a bit of python and a keybaord in DAT.

Take a look at this example to see how that’s working:
base_key_press_to_val.tox (990 Bytes)

You could hack your way there with chops, but it’s less intuitive, and you’ll end up with something that cooks every frame - you’ll end up using something like a hold CHOP to keep the last value - otherwise you’ll always return to 0:
base_val_with_chops.tox (646 Bytes)

Thanks Matthew, this works. But what if I want to use like e.g. 10 diferent keyboard-keys to select 10 values, will the python scrift not get quite complicated? Is there no easier way?

Here’s another approach that might be easier if you don’t want to get too in to editing python.
KeyIndex.toe (3.82 KB)

niknaim79 -

I think it depends on what you mean by easier. If you look at that python callback you’ll see that to add more keys means adding additional elif statements. The benefit here is that you can very precisely control the correlation from key to value. Logically that has a more consistent and more explicit behavior. If you look over the CHOP example that’s certainly another way to tackle that challenge, you just end up with a few fractions of a millisecond for your key watcher operation.

I guess the other question here is where is this fitting into your project - is this a show control interface, is this an interactive installation, is it shortcut building? There might well be an easier approach based on your use case. Does it matter if the value goes back to 0 after the key is released? There’s a node-only approach that would be fine in those conditions, it’s just worth knowing that the nature of the keyboard in CHOP means that you get both and on and off event - what you want generally - I’d just hate to suggest a solution that’s not going to work for your needs.

I’ve attached 3 approaches using a dictionary. You could assign specific values to each dictionary key or if your script is more complicated, assign functions to each key.

If you wanted to avoid defining a dictionary every time you press a key, you could define the keyboard dictionary in an extension.
keyboardExt.tox (1.51 KB)
keyboardFunctionDict.tox (1.13 KB)
keyboardDict.tox (1.14 KB)

Thanks for all your ideas! The Keyboard Dictionary really nice for me.
Finally I managed to create something more “visual” for Keybaord-number-pairs from this idea combined with the “base_key_press_to_val.tox” from Mathew.
Here is my result! (just getting into python)
base_key_press_to_val_niklas.toe (4.08 KB)

Similar to the dictionary example I provided, you can eliminate the if/else statements by using the subscript operator here. You could use a try/except block to handle the exceptions if you aren’t a fan of the membership testing approach.

[code]

define our target as the operator constant1

target = op(‘constant1’)
ziel=op(“KeyShort”)

#retrieve the list of shortcut options to test
keyData = ziel.col(0)

def onKey(dat, key, character, alt, lAlt, rAlt, ctrl, lCtrl, rCtrl, shift, lShift, rShift, state, time):
if state:
#check if it’s in the list otherwise you’ll have multiple exceptions
if key in keyData:
#retrieve the value from the table
target.par.value0=ziel[key,1]

return[/code]

base_key_press_to_val_v2.tox (1.04 KB)