Latest OF modifiers (ctrl, alt,...)

I used to do this:

// keyPressed function
case 's': case 'S':
        // do stuff

This no longer works with the latest OF version, how should we be doing this now?

switch (key) {
		case OF_KEY_UP:
		case OF_KEY_DOWN:
			drone.controller.pitchAmount = 0;
		case OF_KEY_LEFT:
		case OF_KEY_RIGHT:
			drone.controller.rollAmount = 0;
		case 'w':
		case 's':
			drone.controller.liftSpeed = 0;
		case 'a':
		case 'd':
			drone.controller.spinSpeed = 0;

Hi, I meant using modifiers such as ctrl, or shift. Currently I have to sort out which key code is triggered, for instance Ctrl + S triggers number 19 as key.

    case 19:  // <- key code for CTRL + S
        // save... 

I’m guessing there is a different way to do this within OF.

Ah ha. Sorry; that’s what I get for not reading the title.

Maybe an array of booleans that contains every key?

Also, why is what you have not working?

:wink: :thumbsup:

What does not work is the first code sample I posted, neither this one:

    case OF_KEY_CONTROL:
        if(ofGetKeyPressed( 's' )
        {/* do stuff */}

That used to work in 0.8.1. There must be an ofGetModifiers() function or similar, but I can’t find it.

key value 768 is either/both Control key, value 769 is left Control and value 770 is right Control. Related: 1280 is either/both Alt key, 1281 is left Alt key and 1282 is right Alt key, 2304 is either/both Shift key, 2305 is left Shift key and 2306 is right Shift key. I don’t know what happened to the defined constants you were using and why they aren’t working, but that should help in the mean time until you find what you wanted.

EDIT: if you have the console enabled in your program, you can just add this code to your “ofApp::keyPressed” function to see what each key is set as in oF:

cout << "keyPressed " << key << endl;

or this code in your “ofApp::keyReleased” function:

cout << "keyReleased " << key << endl;

(assuming you’re using the project from the project generator)

i’m using if(ofGetKeyPressed(OF_KEY_CONTROL)) with master and it works for me, should work on 0.8.4, which platform are you using?

(Apologies for the delay, I forgot to hit the Reply button… :sweat_smile: )

Hi, yes that works as expected, but it doesn’t while inside a case inside a switch statement, on the keypressed function (see first post)

I’m on Windows, VS 2012.

I am wondering the same thing here, on OSX.

i am on OS X 10.10 with OF 0.8.4.
and it only works soso

//only works if it is pressed first and then control
if(ofGetKeyPressed('a') && ofGetKeyPressed(OF_KEY_CONTROL)){

//works no matter what is pressed first
if(ofGetKeyPressed(OF_KEY_CONTROL) && ofGetKeyPressed(OF_KEY_SHIFT)){
    cout<<"shift "<<ofGetFrameNum()<<endl;