You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all I'd like to thank you for the useful and convenient library!
Though I find it difficult to use with the multiple shortcuts, if you specify same callbacks. The callback can't distinct from which hotkey it is called (using 'identifier' and 'carbonHotKeyID' fields of HotKeyBox is not very convenient in this case)
I've just added two more handlers to HotKey class, and the reference variable:
public typealias RefHandler = (Int?) -> Void
public var keyDownRefHandler: RefHandler?
public var keyUpRefHandler: RefHandler?
public var refCon: Int?
Modified the 'Call the handler' part of handleCarbonEvent()
// Call the handler
if hotKey.isPaused {
return noErr
}
switch GetEventKind(event) {
case UInt32(kEventHotKeyPressed):
if let handler = hotKey.keyDownHandler {
handler()
return noErr
}
if let handler = hotKey.keyDownRefHandler {
handler(hotKey.refCon)
return noErr
}
case UInt32(kEventHotKeyReleased):
if let handler = hotKey.keyUpHandler {
handler()
return noErr
}
if let handler = hotKey.keyUpRefHandler {
handler(hotKey.refCon)
return noErr
}
default:
break
}
And now I'm able to register the multiple hotkeys with the same callbacks!
I'm not very familiar with git so I posted it here in case you want to merge it.
Best regards.
Albert
The text was updated successfully, but these errors were encountered:
I would like to echo the appreciations for this library. Thank you!
An alternative approach to the suggestion here is to use a closure (as a generic handler) that captures which hotkey it has been attached to. You can see a working example behind the two links below:
First of all I'd like to thank you for the useful and convenient library!
Though I find it difficult to use with the multiple shortcuts, if you specify same callbacks. The callback can't distinct from which hotkey it is called (using 'identifier' and 'carbonHotKeyID' fields of HotKeyBox is not very convenient in this case)
I've just added two more handlers to HotKey class, and the reference variable:
Added slightly modified constructors:
Modified the 'Call the handler' part of handleCarbonEvent()
And now I'm able to register the multiple hotkeys with the same callbacks!
I'm not very familiar with git so I posted it here in case you want to merge it.
Best regards.
Albert
The text was updated successfully, but these errors were encountered: