Doh, I'd forgotten about .onKeyPress(). Adding this onto my Table() works fine:
.onKeyPress(.space, action: {
viewModel.extractForQuicklook()
return .handled
})
Post
Replies
Boosts
Views
Activity
CommandGroup(after: .sidebar) {
Button("Quicklook") {
guard activeViewModel != nil else { return }
activeViewModel?.extractForQuicklook()
}
.keyboardShortcut(.space, modifiers: []) // FIXME: This doesn't work if it's .space, but does work if it's "a"
.disabled(activeViewModel?.selectedEntries.count == 0)
Divider()
}
This is how I'm trying to set Space as the keyboard shortcut.
Although weirdly I was rewriting that code in Swift today and it is now also not successfully removing the listener, despite the Remove call returning success. My callback is still getting called.
https://github.com/Hammerspoon/hammerspoon/blob/a20d2d9fb6818e569fcc88791a40d5a6b26a405f/Hammertime/Camera.swift#L207
We use this in our app and it seems to work: https://github.com/Hammerspoon/hammerspoon/blob/70a1cda2d98982c13975194d201bfff431d1bd33/extensions/camera/libcamera.m#L126