How to catch Press and Hold key board event?

How to catch Press and Hold key board event?
0.0 0

#1

I have a function here for moving a Sprite on every key pressed. Now I also want to move it on key hold instead of pressing the key repeatedly but I have no idea how to do it. Please guide me, your help is very much appreciated.

keyBoardListener->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event)
	{
		Vec2 location = event->getCurrentTarget()->getPosition();
		switch (keyCode)
		{
		case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
		case EventKeyboard::KeyCode::KEY_A:
			event->getCurrentTarget()->setPosition(location.x - 10.0f, location.y);
			break;
		case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
		case EventKeyboard::KeyCode::KEY_D:
			event->getCurrentTarget()->setPosition(location.x + 10.0f, location.y);
			break;
		case EventKeyboard::KeyCode::KEY_UP_ARROW:
		case EventKeyboard::KeyCode::KEY_W:
			event->getCurrentTarget()->setPosition(location.x, location.y + 10.0f);
			break;
		case EventKeyboard::KeyCode::KEY_DOWN_ARROW:
		case EventKeyboard::KeyCode::KEY_S:
			event->getCurrentTarget()->setPosition(location.x, location.y - 10.0f);
			break;
		}
	};

#2

use a variable to set value in key down and use that variable to determine if you have to move or not. In key up you reset the variable so that the sprite doesn’t move anymore.