"Undo" keyboard button (iPad/sidecar and other keyboards)


I’m working on my first pull request, and I wanted to share notes I’m taking along the way. (I think devtalk is the best place to share notes like this, but happy to post elsewhere too if there’s a better place.)

Goal: Make the “undo” button from keyboards and iPad (via sidecar) do undo actions in Blender.
Goal reference: Getting the undo button working in sidecar would address one of the issues this rightclickselect post. I commented on some of my feedback as a user who wants sidecar working, too. I’ll share a link to this in a comment hopefully, since new users can only share 2 links lol)

Keystroke → Event type → action (like “ed.undo”)

Two steps:

  1. Register “undo” keystrokes in Blender as an Event type (I could use help here)
  2. Change the default keybindings to map the “undo” Event type do the “ed.undo” action

For (1), I don’t really know where to start. How do keystrokes make it into the list of keystroke events? Is there a library that helps with this, or is it part of clang itself?

For (2), I’m sure I can add a default keybinding entry somewhere around here. This part seems pretty straightforward!

Right-Click Select post for this: Right-Click Select — Blender Community

This file might be related too hmm

More background context for the OSX side at least:

  • We map carbon/cocoa keystrokes to GHOST events in intern/ghost/intern/GHOST_SystemCocoa.mm
  • carbon is the older way, cocoa is the newer way. Carbon keycodes seem to start with kVK_ and cocoa ones seem to start with NS
  • I don’t see a keycode for undo in carbon – looking them up in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h
  • Cocoa seems to offer undo as “NSUndoFunctionKey” (don’t have a full list / canonical reference for this yet, but it came up on this page: Handling Key Events).
  • According to a comment in GHOST_SystemCocoa.mm, there’s an intent to eventually port from carbon to cocoa, a comment says: “/* For the currently not ported to Cocoa keyboard layout functions (64bit & 10.6 compatible) */”.
  • Another comment suggests that carbon and cocoa share keycodes “Converts Mac raw-key codes (same for Cocoa & Carbon)” but I don’t see any reference to that from searching online.
  • Maybe I could just drop in NSUndoFunctionKey into the list that includes entries like kVK_VolumeUp? I don’t think it’ll be quite that easy lol

And that’s where I’m at now!

Thank you LazyDodo filedescriptor and Harleya for helping point me in the right direction in blender.chat :slight_smile: (can’t @-mention people bc I’m a new user lol)

Probably not? If you look at this code from the Chromium project, they have two different functions to convert from kVK_* (DomKeyFromKeyCode using a short keyCode), versus NS* keys DomKeyFromCharCode using a unichar char_code). The second having your NSUndoFunctionKey and NSRedoFunctionKey.