iosswiftmacosipadmac-catalyst

Connecting Keyboard actions to UIButton Actions in Mac Catalyst App


I have a Mac Catalyst App that for the sake of this question, you can assume it's a calculator. Therefore, it has a lot of UIButtons. Everything works fine. But what I really want to do is to connect the physical keyboards actions, for example pressing 1, 2, 3, ... buttons on the keyboard to the corresponding UIButtons for those keys. How can I do that? Again, it's a Mac Catalyst App not a macOS app.


Solution

  • With iOS 13.4, you can use UIResponder's pressesBegan: to catch UIKey based UIEvents

    See https://developer.apple.com/documentation/uikit/mac_catalyst/handling_key_presses_made_on_a_physical_keyboard