Is This What They Call Guerilla Marketing?

I’ve uploaded the ‘Blooper’ reel of Horizon outtakes to YouTube. (Yes, they were faked. My real goofs were boring, not funny.)

On a more serious, painful note, I discovered something odd in the way Cocoa handles keyboard input. You can trap most keyboard events with the keyDown: method. I’m using that to catch the arrow keys for keyboard navigation on the calendar.

The next step was to catch Command (the Apple ‘cloverleaf’ key if you didn’t know the official name) plus the arrow keys to move through the months. Cmd (Command) + left arrow for the previous month, Cmd + right arrow for the next month. Using the event modifier flags I can catch the Command key and make that work. So far so good.

Next, I want Cmd + return to create a new cell or edit an existing cell, and Cmd + delete to delete and existing cell. The keycode for return is 13, just like the old ascii value. And delete is 127. But keyDown: just ignores return, Cmd+return, delete, and Cmd+delete.

The answer turns out to be a different method, performKeyEquivalent:. The documentation on this method is very poorly written, but the gist of it seems to be that the method is intended for custom implementation of keyboard equivalents of menu items. So I can trap Cmd+enter in that method, and Cmd+delete. All I have to do is look for the numeric codes for enter and delete, do my thing, and return YES. I don’t have to check for the modifier key, but I do have to use charactersIgnoringModifiers: instead of just characters: to get at the keycode. The only other odd thing is the Cmd+left arrow, and Cmd + right arrow are not handled here, but back in keyDown:.

If anyone can explain the logic behind this to me, I’d love to hear it.

Leave a Reply

Your email address will not be published. Required fields are marked *