Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for SwiftUI #32

Open
michael-eder opened this issue Feb 14, 2021 · 2 comments
Open

Support for SwiftUI #32

michael-eder opened this issue Feb 14, 2021 · 2 comments

Comments

@michael-eder
Copy link

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

@glouel
Copy link

glouel commented Jul 4, 2021

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())")
        }
    }
    ...
}

@Aayush9029
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants