How to execute stuff as long as a key is pressed down

I was trying to execute some code (In this case move the texture a couple of pixels) but I ran into a problem. There are functions keyDown() and keyUp() but I couldn’t find anything like keyHold() or keyPressed(). How is it possible to execute some code only when a key is pressed down and stop when it’s released?
Here is my failed attempt at achieving it. (I had no idea how to)

#include <cinder/app/App.h>
#include <cinder/app/RendererGl.h>
#include <cinder/Rand.h>
#include <cinder/ImageIo.h>
#include <cinder/app/KeyEvent.h>
#include <cinder/gl/draw.h>
#include <cinder/gl/wrapper.h>
#include <filesystem>
#include <glm/fwd.hpp>

using namespace ci;
using namespace ci::app;


class BasicApp : public App {
  public:
	void setup() override;
	void update() override;
	void draw() override;
	void resize() override;
	void keyUp(KeyEvent keyEvent) override;
	void keyDown(KeyEvent keyEvent) override;

	gl::TextureRef texture;
	float x,y,z;
	bool isKeyUp;
};

void prepareSettings( BasicApp::Settings* settings ) 
{
	settings->setWindowSize(1000,700);
}

void BasicApp::setup() 
{
	fs::current_path("/home/archspect/Code/Cinder/BasicApp/");
	texture = gl::Texture::create(loadImage("assets/texture.png"));
}

void BasicApp::resize()
{
	gl::setMatricesWindow(getWindowSize());
}

void BasicApp::update() {}

void BasicApp::keyUp(KeyEvent keyEvent)
{
	if(keyEvent.KEY_UP)
	{
		isKeyUp = true;
	}
}

void BasicApp::keyDown(KeyEvent keyEvent)
{
	if (keyEvent.KEY_UP)
	{	
		isKeyUp = false;
		if (!isKeyUp)
		{
			x++;
			y++;
		}
	}
}
void BasicApp::draw()
{
	gl::clear();
	gl::draw(texture, vec3(x,y,z));
	
}
CINDER_APP( BasicApp, RendererGl, prepareSettings )

You’re very close, you just need to move your logic for what happens when isKeyUp == true to somewhere that is called every frame, like BasicApp::update() or BasicApp::draw().

Also, the way to check for specific key events is:

if ( keyEvent.getCode() == KeyEvent::KEY_UP )`
{
//...
}

Right now you’re just evaluating whether the constant value for KEY_UP is not zero, which is always true :slight_smile:

A