MacOS 'paste' into ofxInputField not recognised


I’ve added an ofxInputField<std::string> to an ofxGui. It works except when trying to copy/paste text values from the field.

I’m running of_v0.11.2_osx_release on an M1 Macbook Pro MacOS v11.6 latest update.

I set a breakpoint in ofxInputField.keyPressed to debug.

I notice two oddities:

  • we test for OF_KEY_CONTROL rather than the more MacOS-native OF_KEY_COMMAND for the paste action (and other command actions)
  • when the code runs after pressing “Ctrl-V” (not Command-V), it seems that key == 'V' rather than the ‘v’ that is looked for in the code

The result is that the normal “command-key” actions are not recognised in keyPressed and fail to work.

When I replace OF_KEY_CONTROL with OF_KEY_COMMAND inside keyPressed, the normal actions work fine.

Is this a peculiarity of my setup (vanilla except for running an M1 machine), or a deliberate decision that doesn’t match my expectation, or an oversight that might require a platform-specific change to use OF_KEY_COMMAND instead of OF_KEY_CONTROL when building for MacOS.


noh, catching these is a bit of a pain.

i’ve been using this in production for many years:

#if defined(TARGET_OSX)


// note that on windows ctrl+a is a new character, it does not show directly as ctrl, then a. if you want to work with event.key, then this might help: 
#ifdef _WIN32
	if (ofGetKeyPressed(OF_KEY_CONTROL) && key.key >= 1 && key.key <= 26) {
		key.key = key.codepoint = 'a' + (key.key - 1);

// check for ctrl/cmd+v
if(ofGetKeyPressed(MUI_KEY_ACTION) && key.codepoint == 'v'){ ... }

note that some shortcuts use ctrl on osx (e.g. ctrl+a/ctrl+e to jump to beginning/end of line). actually it would be great to have a list of interactions for each OS, e.g. here is what i know about the textfield in osx:

cmd+c copy
cmd+v paste
cmd+x cut
cmd+z undo
cmd+shift+z/cmd+y redo
cmd+a select all
cmd+left/ctrl+a cursor to start of line
cmd+right/ctrl+e cursor to end of line
cmd+up cursor to start of file
cmd+down cursor to end of file
alt+left jump left one word
alt+right jump right one word
shift+left select one more character to the left
alt+shit+left select on more word to the left
shift+right select one more character to the right
alt+shift+right select on more word to the right
shift+up select one more line up
shift+down select on more line down
cmd+shift+left select everything to the start of the line
cmd+shift+right select everything to the end of the line
cmd+shift+up select everything to the start of the document
cmd+shift+down select everything to the end of the document
click move cursor to this place
double click select word around cursor
tripple click select paragraph/line
click+drag make selection
double click+drag make selection on word boundaries
tripple click+drag make select on paragraph/line boundaries
right click brings up the context menu (cut/copy/paste)

i’m still missing a few (most notably, for me, double click to select a word), but you can see my stb_textedit implementation here:

That’s an interesting addon you’ve got there! I’m a relative newbie but see how adding lots of controls to a generative piece is necessary… your library looks very interesting in that context, so thank you. I’ll be taking a deeper look in my next project for sure. :grinning: