swiftkeyboardkeyboard-eventskeycode

Swift - keycode keyboardReturn not working


I have hotkeys on my app when using a physical keyboard and all the keys work fine except for the return key. Is there a reason why or a workaround to make this work? Thanks.

extension testViewController {
  override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
  guard let key = presses.first?.key else {return}
    
  if key.keyCode == .keyboardReturn {
        print("KEY PRESSED \(key.debugDescription)")
    }
  }
}

Solution

  • There are two keycodes for return which are .keyboardReturn and .keyboardReturnOrEnter

    I just had to use .keyboardReturnOrEnter which I didn't see at the time.