HotKey icon indicating copy to clipboard operation
HotKey copied to clipboard

Support for SwiftUI

Open michael-eder opened this issue 4 years ago • 2 comments

Do you plan to support SwiftUI (or even extend the documentation, how to integrate into SwiftUI)?

michael-eder avatar Feb 14 '21 14:02 michael-eder

Not author, but you can use the code in an init() of a view (or app) directly, just make sure, as was pointed in another issue, to make the hotkey reference a class variable.

Looks like this in the App :

struct MyApp: App {
    let hotKey: HotKey
    
    init() {
        // Setup hot key for ⌥⌘R
        hotKey = HotKey(key: .r, modifiers: [.command, .option])
        
        hotKey.keyDownHandler = {
            print("Pressed at \(Date())")
        }
    }
    ...
}

glouel avatar Jul 04 '21 17:07 glouel

I've used .onAppear and it seems to work well

Aayush9029 avatar Sep 02 '21 22:09 Aayush9029