Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

How to move slider bar of ofxSlider using keyPressed

$
0
0

@DeepErGo wrote:

I drew a slider bar using ofxSlider. The ofxSlider object is working well with my mouse button signal. What I want to implement is to make the slider bar interacting with my key pressed such as moving +1 when the right arrow key is pressed and -1 when the left arrow key is pressed. How do I implement this?

ofApp.cpp

void ofApp::setup(){
	// ****** GUI Stuff
	slider.addListener(this, &ofApp::seekBarChanged);	
	gui.setup();
	gui.add(slider.setup("Frame", 0, 0, 0));
}
...
void ofApp::seekBarChanged(int &pos) {
       // Something to do
}
...
void ofApp::keyPressed(int key){
	if (key==OF_KEY_LEFT) {		// left arrow key
		leftIsDown = true;
	}
	if (key == OF_KEY_RIGHT) {	// right arrow key
		rightIsDown = true;
	}
}

void ofApp::keyReleased(int key){
	if (key == OF_KEY_LEFT) {	       // left arrow key
		leftIsDown = false;
	}
	if (key == OF_KEY_RIGHT) {	// right arrow key
		rightIsDown = false;
	}
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles