autr
January 20, 2018, 2:17pm
1
Hello, in 0.10 w. High Sierra I’m not registering two keypresses when a modifier key is also pressed. For example;
void ofApp::keyPressed( ofKeyEventArgs& e) {
ofLog() << "ofApp::" << (e.key == 'a') << (ofGetKeyPressed(OF_KEY_COMMAND));
};
Log output is;
ofApp:: 0 1 // cmd is pressed
ofApp:: 0 1 // + a is pressed
Same for permutations
ofLog() << "ofApp::" << (ofGetKeyPressed('a')) << (ofGetKeyPressed(OF_KEY_COMMAND));
// etc
Though it works for two non-modifier keys…
you should try ofxModifierKeys https://github.com/satoruhiga/ofxModifierKeys
I’m not sure if is still works on high sierra.
arturo
January 22, 2018, 11:55am
3
in 0.10 you can now check the modifiers in the event as:
void ofApp::keyPressed( ofKeyEventArgs& e) {
e.hasModifier(OF_KEY_COMMAND)
}
2 Likes
autr
August 6, 2018, 8:20pm
4
Hmm, still unable to get this to work - I’m in a blank project, OF 0.10.0 with High Sierra;
void ofApp::keyPressed(ofKeyEventArgs& e){
if (e.key == 's') {
ofLog() << "Left" << e.hasModifier(OF_KEY_LEFT_COMMAND);
ofLog() << "Any" << e.hasModifier(OF_KEY_COMMAND);
ofLog() << "Right" << e.hasModifier(OF_KEY_RIGHT_COMMAND);
}
}
Event fires if CMD isn’t held down, doesn’t fire if it is held down?
hamoid
August 6, 2018, 8:45pm
5
Is this recent commit related?
1 Like
arturo
August 7, 2018, 8:38am
6
@autr yes this is a problem with 0.10 in macos. It’s solved already in github and should work with today nightly build and the next official release which should happen soon
2 Likes
autr
August 7, 2018, 7:10pm
7
Ah, thank you for the pointer
I having this problems too. macOS Sierra and OF Github repo.
I tried too to replace ‘eventArgs.key’ to ‘eventArgs.codepoint’ but nothing changes…
(Is not an ofApp, but a class with they own key listeners)
On my if/else tree, only the first two (//action 1 & //action 2) are detected…
Any idea?
void myClass::keyPressed(ofKeyEventArgs &eventArgs)
{
const int &key = eventArgs.key;
//uint32_t key_codePoint = eventArgs.codepoint;
bool mod_ALT = eventArgs.hasModifier(OF_KEY_ALT);
bool mod_SHIFT = eventArgs.hasModifier(OF_KEY_SHIFT);
if (mod_SHIFT && key == ' ')
{
//action 1
}
else if (key == ' ')
{
//action 2
}
else if (mod_ALT && key == 'p')
{
//action 3
}
else if (key == 'p')
{
//action 4
}
else if (mod_ALT && key == 's')
{
//action 5
}
else if (key == 's')
{
//action 6
}
...
}
void ofxFontAnimator::keyPressed(ofKeyEventArgs &eventArgs)
{
int key = eventArgs.codepoint;
//int key = eventArgs.key;
bool mod_COMMAND = eventArgs.hasModifier(OF_KEY_COMMAND);
bool mod_CONTROL = eventArgs.hasModifier(OF_KEY_CONTROL);
bool mod_ALT = eventArgs.hasModifier(OF_KEY_ALT);
bool mod_SHIFT = eventArgs.hasModifier(OF_KEY_SHIFT);
ofLogNotice("ofxFontAnimator") << "key: " << key;
ofLogNotice("ofxFontAnimator") << "COMMAND: " << (mod_COMMAND ? "+" : "");
ofLogNotice("ofxFontAnimator") << "CONTROL: " << (mod_CONTROL ? "+" : "");
ofLogNotice("ofxFontAnimator") << "ALT: " << (mod_ALT ? "+" : "");
ofLogNotice("ofxFontAnimator") << "SHIFT: " << (mod_SHIFT ? "+" : "");
ofLogNotice();
When pressing ‘p’ key I get:
[notice ] ofxFontAnimator: key: 112
[notice ] ofxFontAnimator: COMMAND:
[notice ] ofxFontAnimator: CONTROL:
[notice ] ofxFontAnimator: ALT:
[notice ] ofxFontAnimator: SHIFT:
But when pressing ALT+‘p’:
[notice ] ofxFontAnimator: key: 960
[notice ] ofxFontAnimator: COMMAND:
[notice ] ofxFontAnimator: CONTROL:
[notice ] ofxFontAnimator: ALT: +
[notice ] ofxFontAnimator: SHIFT:
key differs from 112 to 960 so is changing when shouldn’t do.