Count up and down using keyboard in

Hello,

I’m trying to build a simple slideshow where one keyboard button will move you left to right through the slides and another will move you right to left. I can manage to move one direction by using a counter and switch nodes but the logic to move back through the slides eludes me.

please help

Can you upload what you’ve built so far?

Here’s what I’ve got so far. This will move me up through the numbers - what can I do to make another key move down?

slideShowSwitchUp.toe (4.13 KB)

Hi martincoyne,

Sometimes a little bit of python is easier for these kinds of tasks. If drop down a keyboard in DAT, and a constant CHOP, try replacing your onKey callbacks with this:

counter 		= op('constant1')

def onKey(dat, key, character, alt, lAlt, rAlt, ctrl, lCtrl, rCtrl, shift, lShift, rShift, state, time):
	if state:
		if key == "right":
			counter.par.value0 = counter[0] + 1
		elif key == "left":
			counter.par.value0 = counter[0] - 1
		else:
			pass
	else:
		pass

	return

The idea would be that the right arrow key counts up, and the left arrow key counts down. With a little more python you could add in a reset function for another key press, and also set limits for how far it would count up or down.

Thanks ragamnd,

Tried that but its not working for me - I’m obviously doing something wrong! Could you upload a file example please?

much gratitude

base_arrow_key_advance.tox (1.08 KB)

Here’s a functioning example. Your left and right arrow keys add and subtract from the value0 in constant1.

Learning some python in the context of Touch is pretty important - in my opinion - if you want to make meaningful progress. There’s a set of tuts up here to help you get your feet wet in that process if you’re interested:
matthewragan.com/teaching-resou … hdesigner/

Beautiful,

thank you Raganmd, learning Python here I come…

Hi! just reading this in 2023 but posting the answer if anyone searches for it, using two keys for counting up and down is pretty straightforward just using nodes, without python!

First you need to get your two keys with your keyboard CHOP (here to get the arrow keys you can just type “left” and “right”), then a count CHOP that will count the number of times that each keys have been pushed. Last step is to put a math CHOP, set “combine channels” to “substract” and you’re done!

If the order is reverse either change the order of left and right in the keyboard in CHOP, or multiply by -1 in the math CHOP.

I hope that someone that don’t like using python like me can find this useful, cheers!

1 Like

Hi @Neurotypique,

another optimization could be to use the 3rd Input of the Count CHOP: “Increment Value”. So depending on which key you press, you could pass in a 1 or a -1 automatically doing it all in a single Count CHOP.

cheers
Markus

1 Like